问题
i'm new to android and i have a question. i'm using a SimpleAdapter with a ViewBender to display images and text. However i cant figure out how to set up the OnItemClickListener for the SimpleAdapter. How do i do it? This is how i initialize it:
SimpleAdapter notes = new SimpleAdapter(Main.this, list, R.layout.main_list_row, PARAM, new int[] { R.id.icon, R.id.name, R.id.content });
notes.setViewBinder(new MyViewBinder());
setListAdapter(notes);
thanks in advance
回答1:
Try below code I think you are extending your Activity with ListActivity
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
来源:https://stackoverflow.com/questions/5112758/how-to-get-onitemclicklistener-for-simpleadapter-working