Button in ListView using ArrayAdapter

后端 未结 1 1492
感情败类
感情败类 2021-01-27 20:25

I have a ArrayAdapter which is populated using a POJO class. The listview comprises of 2 layout. 1 is for a menuitem and one is for the category. The Listview with seperator is

相关标签:
1条回答
  • 2021-01-27 21:08

    Within getView() method you have to set tag to your button and when you click on button get the tag within integer, it will return you correct position of your button click, something like below.

    else {
            holder = (ViewHolder) convertView.getTag();  
    }   
    holder.edit.setTag(position);  //to get the orignal position later in onClick() of button
    holder.edit.setOnClickListener(new View.OnClickListener() {  
              public void onClick(View v) {   
                     int pos = (Integer) v.getTag();  //the real and updated position
                 Log.i("ConfirmAdapter ","Order Edit @ position : " + pos); 
              }       
    });  
    

    Updated

    Note: after getting convert-view tag, set the tag to your button and handle click even too.

    What is the main purpose of setTag() getTag() methods of View?

    0 讨论(0)
提交回复
热议问题