How to get OnItemClickListener for SimpleAdapter w

2019-06-02 10:36发布

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条回答
狗以群分
2楼-- · 2019-06-02 10:50

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();
    }
  });
查看更多
登录 后发表回答