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

后端 未结 3 1962
悲&欢浪女
悲&欢浪女 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:11

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

    I need to set visible an element from the same parent so I used this code :) and it worked

提交回复
热议问题