ユーザーがリストビューのアイテムをクリックすると、その機会に動的に作成された別のクラスに移動するようにしようとしています。追加するには、連絡先リストアプリを作成しています。ユーザーがアプリをクリックすると、システムを通過したテキストと通話履歴が表示されます。これを行う方法がわかりません。ガベージコレクターメソッドがうまく機能すると思いますが、コンテキストが間違っていると思います。
ありがとう :)
コード:
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;
}
}
}