【发布时间】:2014-02-10 11:13:59
【问题描述】:
我有一个加载了 AsyncTask 的 CustomListView。 我在每一行的末尾都有一个 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(),还有我的 SimpleAdapter:
@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()方法中实现它。
标签: java android android-listview onclicklistener imagebutton