2

I am adding a drawable image as header in listview. I have implemented it as follows in case of an activity.

listView1 = (ListView)findViewById(R.id.listView1);

    View header = (View)getLayoutInflater().inflate(R.layout.header, null);
    listView1.addHeaderView(header);

However, now i am trying to implement the same in a viewpager fragment like this

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ShowFrag1 extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v=inflater.inflate(R.layout.frag1, container,false);
        ListView lv1=(ListView) v.findViewById(R.id.listView1);

        Level weather_data[] = new Level[]
                {
                    new Level(R.drawable.s1, "L1", R.drawable.p),
                    new Level(R.drawable.s2, "L2",R.drawable.p),
                    new Level(R.drawable.s3, "L3",R.drawable.p),
                    new Level(R.drawable.s4, "L4",R.drawable.p),
                    new Level(R.drawable.s6, "L5",R.drawable.p)
                };
        LevelAdapter adapter = new LevelAdapter(getActivity(),
                R.layout.list_item, weather_data);

       View header = (View)getLayoutInflater().inflate(R.layout.header, null);
        lv1.addHeaderView(header);

        lv1.setAdapter(adapter);
        return v;
    }
}

Now in this, i am getting an error "

The method getLayoutInflater(Bundle) in the type Fragment is not applicable for the arguments ()

" in the line

View header = (View)getLayoutInflater().inflate(R.layout.header, null);

How do i resolve this error? Thanks

1 Answer 1

3

Change

View header = (View)getLayoutInflater().inflate(R.layout.header, null);

with

  View header = inflater.inflate(R.layout.header, null);

the first paramter of onCreatView is a LayoutInflater

Sign up to request clarification or add additional context in comments.

1 Comment

yes of course. That's depends on how did you wrote R.layout.header

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.