Button in ListView using ArrayAdapter

房东的猫 提交于 2019-12-02 10:22:34
RobinHood

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?

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