我有一個使用AsyncTask加載的CustomListView。 我有一個imageButton到每一行的末尾。如何在自定義ListView中獲取位置並設置ImageButton的偵聽器
我的問題:當我點擊我的imageButton時,沒有任何工作。 我試過很多的解決方案是這樣的:
Android : how to set listener and get position of imagebutton click in a custom adapter
我的ListView類誰打電話的AsyncTask:
public class listview extends Activity {
private ListView maListViewPerso;
ImageButton imgButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color
.parseColor("#000000")));
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
asyncTask asynchrone_task_tournee = new asyncTask(listview.this, maListViewPerso);
asynchrone_task_tournee.execute();
}
這是我的ImageButton我想要得到的位置,並設置一個監聽..
EDIT 1(回答評論)這是我的onPostExecute()
並有我的SimpleA dapter:
@Override
protected void onPostExecute(JSONArray jArray) {
super.onPostExecute(jArray);
JSONObject json_data=null;
HashMap<String, String> map;
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
this.pDialog.dismiss();
Log.i("JSON_TOURNER",jArray.toString());
for(int i=0;i < jArray.length();i++)
{
try {
json_data = jArray.getJSONObject(i);
map = new HashMap<String, String>();
map.put("titre", json_data.getString("time"));
map.put("description", json_data.getString("date"));
map.put("begin_hour", json_data.getString("hour"));
map.put("end_hour", json_data.getString("hour"));
listItem.add(map);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SimpleAdapter mSchedule = new SimpleAdapter (Mycontext, listItem, R.layout.list_type_tournee,
new String[] {"titre", "description","begin_hour","end_hour"}, new int[] {R.id.miscellaneous, R.id.infos,R.id.begin_hour,R.id.end_hour});
listview.setAdapter(mSchedule);
}
哪裏是你'ListAdapter'碼的我的父母直線?你可以在'getView()'方法中實現它。 – SMR