Error: Non-static method 'findViewById(int)' cannot be referenced from a static context

后端 未结 5 1807
天命终不由人
天命终不由人 2020-12-31 05:27

I am using Android Studio (Beta), and while using this java code in \'onCreateView()\', I get an error.

ListView listView = (ListView) findViewById(R.id.some         


        
5条回答
  •  没有蜡笔的小新
    2020-12-31 06:19

    Inside Activity class

     static ListView listView;
     listView = (ListView) this.findViewById(R.id.someListView);
    

    OR

    to create inside fragmentClass(static)

      static ListView listView;
      listView = (ListView) getActivity().findViewById(R.id.someListView);
    

提交回复
热议问题