gpt4 book ai didi

android - 在执行 onPostExecute(Void result) android 之后调用 onListItemClick()

转载 作者:行者123 更新时间:2023-11-30 03:54:07 26 4
gpt4 key购买 nike

我在执行 onPostExecute(Void result) 后调用 onListItemClick() 函数时遇到问题

下面是我的代码 fragment 。

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() 函数,以便我可以在每个项目点击时调用另一个 Activity 。

任何帮助都将不胜感激。

最佳答案

删除

public void onListItemClick(ListView listView , View v , int position , long id){
System.out.println("position------------"+placeName[position]);
}

来自类 GetPlaces

并放入CheckoutNearestPlaces

关于android - 在执行 onPostExecute(Void result) android 之后调用 onListItemClick(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13610961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com