onPostExecute(Void result) の実行後に onListItemClick() 関数を呼び出すのに問題があります
以下は私のコードスニペットです。
package com.myapp.checkoutnhangout;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class CheckoutNearestPlaces extends ListActivity {
private String[] placeName;
private String[] imageUrl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new GetPlaces(this,getListView()).execute();
}
class GetPlaces extends AsyncTask<Void, Void, Void> {
Context context;
private ListView listView;
private ProgressDialog progressDialog;
public GetPlaces(Context context , ListView listView) {
this.context = context;
this.listView = listView;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(context);
progressDialog.setIndeterminate(true);
progressDialog.setTitle("Loading");
progressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
findNearLocation();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
progressDialog.dismiss();
setListAdapter(new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,placeName));
// this.listView.setAdapter(new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,placeName));
}
public void onListItemClick(ListView listView , View v , int position , long id){
System.out.println("position------------"+placeName[position]);
}
public void findNearLocation() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
PlacesService placesService = new PlacesService("AIzaSyC3y3fOMTqTkCjNNETQTCKustG7BRk_eVc");
List<Place> findPlaces = placesService.findPlaces(28.6752, 77.4362, "");
int findPlacesSize = findPlaces.size();
placeName = new String[findPlacesSize];
imageUrl = new String[findPlacesSize];
for(int index = 0 ; index < findPlacesSize ; index ++) {
Place placeDetail = findPlaces.get(index);
// System.out.println("name of place : "+placeDetail.getName());
placeName[index] = placeDetail.getName();
// System.out.println("url of place : "+placeDetail.getIcon());
imageUrl[index] = placeDetail.getIcon();
}
}
}
}
上記のコードは google palce api を使用し、ユーザーの関心に基づいて場所のリストを表示します。その後、 onListItemClick() function を呼び出して、アイテムのクリックごとに別のアクティビティを呼び出すことができるようにします。
どんな助けもかなりのものです。