findViewById() not working in a not MainActivity class

后端 未结 4 1452
耶瑟儿~
耶瑟儿~ 2020-12-13 18:46

I have a text view in my Lyout and I would like to set some text to this textview. This should be made in a class which is not a MainActivity class.

The problem is t

4条回答
  •  半阙折子戏
    2020-12-13 19:26

    You have not set the content View yet?


    to do this use something like this:

    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
    
        }
    
    
    }
    

提交回复
热议问题