Android::findViewByID - how can I get View of a TextView through a Listener of another UI element?

后端 未结 3 1968
悲&欢浪女
悲&欢浪女 2021-02-12 17:32

This is going to be a bit lame question. I have the following code:

..............
 public void onCreate (Bundle bundle)
 {
  super.onCreate(bundle);
  this.setC         


        
3条回答
  •  不知归路
    2021-02-12 18:28

    You could try this:

    class ButtonListener implements android.view.View.OnClickListener {
        public void onClick(View v) {
            View parent = (View)v.getParent();
            if (parent != null) {
                TextView txtView = parent.findViewById(R.id.mytextview);
                txtView.setText(...);
            }
        }
    }
    

    the usage depends on your layout. Its possible, that the parent of your button is not the parent of your textview so be careful...

提交回复
热议问题