OnItemCLickLIstener doesn't work on ListView

前端 未结 3 1048
余生分开走
余生分开走 2021-01-26 02:44

I have an activity with a ListView. ListView with custom views. I add OnItemClickLIstener to the ListView. and when i click on item, in result i see nothing. Activity with ListV

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 03:14

    I guess you are not getting the item the right way. Try this:

    int position = (int) adapterView.getSelectedItemId();
    Log.i("Position:", Integer.toString(position));
    

    Edit

    Try this piece of code.

    ListView lv = (ListView)findViewById(R.id.chat_list);
    lv.setOnItemClickListener(new OnItemClickListener(){
           @Override
           public void onItemClick(AdapterView parent, View v, int position, long id) { 
    
                 int position = (int) parent.getSelectedItemId();
                 Log.i("Position:", Integer.toString(position));
           }
    });
    

提交回复
热议问题