我正在努力做到这一点,一旦用户单击我的列表视图中的一个项目,它就会转到另一个为该场合动态创建的类。要添加,我正在创建一个联系人列表应用程序,当用户单击该应用程序时,它会显示通过我们系统的文本和通话记录;我不知道该怎么做,我猜垃圾收集器方法工作得很好,虽然,我认为这是错误的上下文。
谢谢 :)
代码:
public class ChatService extends ListActivity {
String GotPass;
String GotUname;
public static final String PREFS_NAME = "MyPregs";
private GetTask getTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getTask = new GetTask();
getTask.execute();
}
public class GetTask extends AsyncTask<Void, Void, ReturnModel> {
@Override
protected ReturnModel doInBackground(Void... params) {
return load();
}
@Override
protected void onPostExecute(ReturnModel result) {
if(result.passworderror == true)
{
Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "yaya", Toast.LENGTH_SHORT).show();
ListView lv = getListView();
lv.setTextFilterEnabled(true);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, result.getheadlines());
setListAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getApplicationContext(), "Yaya, we clicked on something", Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
});
}
}
}
private ReturnModel load() {
ReturnModel returnModel = new ReturnModel();
BufferedReader in = null;
String data = null;
Bundle gotData = getIntent().getExtras();
if (gotData != null) {
GotPass = gotData.getString("key!");
GotUname = gotData.getString("key!!");
}
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String username = settings.getString("key1", null);
String password = settings.getString("key2", null);
// username = "irock97"; // unremark to test like you got username from prefs..
if (username != null && username.equals("irock97")) {
returnModel.setPassworderror(false);
}
else
{
returnModel.setPassworderror(true);
return returnModel;
}
HttpClient httpclient = new DefaultHttpClient();
/* login.php returns true if username and password is equal to saranga */
HttpPost httppost = new HttpPost("http://gta5news.com/login.php");
try {
// Add user name and password
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
Log.w("HttpPost", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = "";
while ((l = in.readLine()) != null) {
sb.append(l + nl);
}
in.close();
data = sb.toString();
List<String> headlines = new ArrayList<String>();
headlines.add(data);
returnModel.setheadlines(headlines);
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return returnModel;
}
public class ReturnModel {
private List<String> headlines;
private boolean passworderror;
public List<String> getheadlines() {
return headlines;
}
public void setheadlines(List<String> headlines) {
this.headlines = headlines;
}
public boolean getPassworderror() {
return passworderror;
}
public void setPassworderror(boolean passworderror) {
this.passworderror = passworderror;
}
}
}