How to get OnItemClickListener for SimpleAdapter working

僤鯓⒐⒋嵵緔 提交于 2019-12-08 06:40:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!