How to get the parent view of a button within a list adapter?

跟風遠走 提交于 2019-12-01 14:00:05

You can set the text view to be the tag of the button, that makes it much easier. Like this: In the getView:

TextView textView = ((TextView)  view.findViewById(R.id.textListView)).setText(item.getNome());


    ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton1);
    ib.setOnClickListener(this);
     ib.setTag(textView);

In the onClickListener:

 public void onClick(View v) {
    TextView texto = (TextView) v.getTag();
    texto.setText("CHANGE");
  }
Jachu

For example for a checkBox (same for the rest of views): View viewParent = (View)checkBox.getParent();

But you would like to do might be easier, check this post: OnItemClick listener not working in Custom ListView

Good luck :)

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