When putting listview inside a RelativeLayout it always looking for R.id.list

209 Views Asked by At

I was trying to put an imageview and a listview inside a relative layout, but i'm always having an error like this

Your content must have a ListView whose id attribute is 'android.R.id.list'

then i tried just putting ListView as the parent and it works but i want to display an image above the listview.

here is my xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/header"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/header" />

<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</ListView>

Here is my fragment

public class Tab_About extends ListFragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.tab_about, container,
            false);

    Resources res = getResources();

    final String[] values = res.getStringArray(R.array.about_list);
    Integer imageId = R.drawable.accessory_arrow;

    ListView list = (ListView)rootView.findViewById(R.id.list);

    CustomListAdapter cus = new CustomListAdapter(getActivity(),values, imageId);
    list.setAdapter(cus);


    AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Context context = getActivity().getApplicationContext();
            CharSequence text = "You clicked " + position;
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    };

    // Setting the item click listener for the listview
    list.setOnItemClickListener(itemClickListener);

    return rootView;
}
}

how can i do it? thank you for the help

1

There are 1 best solutions below

1
On BEST ANSWER

The reason it is asking for android:id="@id/android:list" is because you are extending your Fragment with ListFragment, read the documentation here ListFragment Documentation

you can simply extend your Fragment class with Fragment instead of ListFragment.