Using findViewById inside a Fragment

Maven

I am creating a new Tab interface and for every tab I have functionality like:

public class ClassViewFragment extends Fragment {
    ListView classListView = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.class_view, container, false);

        classListView = (ListView) findViewById(R.id.classList);

        return rootView;
    }
}

But I am getting cannot resolve method findViewById also at another place I am also unable to use runOnUiThread and getting Error:(88, 29) error: cannot find symbol method runOnUiThread(<anonymous Runnable>)

I understand these will work fine if my class was extended from Activity but it’s a tab fragment so how can I use this funcitons?

tyczj

you need

classListView = (ListView) rootView.findViewById(R.id.classList);

as that is the view you are concerned with

to get runOnUiThred you need to do getActivity().runOnUiThread

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to replace Fragment inside ViewPager, using PagerAdapter?

From Dev

findViewById is not defined by Fragment

From Dev

FindViewByID Fragment Null

From Dev

Using ActionBar Inside Fragment class in android

From Dev

Using GridView inside Fragment with ArrayAdapter<String>

From Dev

Android fragment - findViewById returns null

From Dev

FindViewbyId always returns Null in Fragment

From Dev

android - findViewById NULL under using Fragment

From Dev

Using Google Maps inside a Fragment in Android

From Dev

Using TabLayout inside a Fragment; tab text invisible

From Dev

View.findViewById in fragment class

From Dev

NullPointerException on findViewById on fragment replacement

From Dev

findViewById returns null in fragment class

From Dev

Radio Button findViewById within a Fragment

From Dev

Using GridView inside View Pager Fragment

From Dev

findViewById is not defined by Fragment

From Dev

findViewById for inactive Fragment tabs

From Dev

Using a Fragment inside my ArrayAdapter

From Dev

FindViewByID Fragment Null

From Dev

Sherlock fragment findViewById() and getIntent() error

From Dev

Android 4.4.2: Using Listview with combobox inside Fragment

From Dev

findViewById in Fragment returns Null

From Dev

Android - Fragment findViewById() always null?

From Dev

FindViewbyId always returns Null in Fragment

From Dev

Using TabLayout inside a Fragment; tab text invisible

From Dev

findViewById returns null in fragment class

From Dev

Image slider inside fragment child using ViewFlipper

From Dev

what do i use instead of findViewById in onCreateView using fragment

From Dev

Calling findViewById in fragment returns null

Related Related

HotTag

Archive