How to get rowID of custom ListView's selected row's child?

倖福魔咒の 提交于 2019-12-09 01:12:27

Try adding this to your adapter:

public class MyAdapter extends BaseAdapter
{
   public static HashMap<Integer,String> myList=new HashMap<Integer,String>();
   ...
   @Override
   public View getView(final int position, View convertView, ViewGroup parent) 
   {
      ...
      myList.put(position,String.valueOf(data.get(position).getID()));     

      return convertView;
   }      
   ...
}

Now in your activity,

public class viewnameactivity extends Activity 
{
   ...
   listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent,View v,int position,long id) {                       
                pos = adapter.getUserArray(position);

                String TVID=MyAdapter.myList.get(position); // this will give you tvid for each listitem
            }
   });
   ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!