Assigning ID to a Row in an Android ListView

后端 未结 4 1271
天涯浪人
天涯浪人 2020-12-28 22:20

I have a ListView. When an item on the ListView is tapped, it loads a SubView. I want to assign an ID to each row of the ListView, so I can pass that ID along to the SubView

4条回答
  •  清酒与你
    2020-12-28 22:57

    Hi Chris you already have the position id in your listView, implement the onListItemClick() function.

        protected void onListItemClick(ListView l, View v, final int position, long id) {
          super.onListItemClick(l, v, position, id);               
          Toast.makeText(this,  "my id to pass along the subview is " + position,Toast.LENGTH_LONG).show();
    
       }
    

    if you want assing your own id use setTag()

    v.setTag("myownID"+position);
    

提交回复
热议问题