Android ListView / ListFragment amplifies one line per line (Java code)

I can't seem to find a solution to this supposedly simple problem / error, so here it is:

A ListFragment of type (android.R.layout.simple_list_item_checked) which, when clicked, loads other fragments and does other work.

The problem is that lines in the ListFragment that are out of sight are "wrapped" to the next line for no apparent reason when scrolling back in the view. Better illustrated with photos below:


Photo 1: Normal condition

1-normal


Photo 2: The list scrolls down - everything works fine (Lamborghini is not displayed) 2-normal-end


Photo 3: However, when I selected Porsche and scrolled down, the text "Mustang" was damaged

4-error1


Photo 4. So, "Lamborghini" when scrolling back after accidentally pressing

5-error2


The codes I used to create the list are pretty simple:

 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        getListView().setHorizontalFadingEdgeEnabled(true);
        getListView().setVerticalFadingEdgeEnabled(true);
        getListView().setFastScrollEnabled(true);
        carsTitleAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_checked, CarModels.Models);
        setListAdapter(carsTitleAdapter);

      

String in CarModels.class

   public static final String[] Models = {
    "Porsche",
    "Lamborghini",
    "Ferrari",
    "McLaren",
    "Aston Martin",
    "Jaguar",
    "Audi",
    "Mustang",        
};

      

I tried to call notifyDataSetChanged () at the end of onListItemClick (), hoping that it will update the list, but the problem still persists. Any possible solutions? Thank!

PS: I am running it on Galaxy Tab 10.1, Honeycomb 3.1 with support-library-v4. Maybe this is a bug in this assembly?

+3


source to share


1 answer


I solved the problem by overriding onCreateView and passing in the layout file that contains the ListView with android: id = "@android: id / list" in the view that is returned from the method.

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.list_fragment_layout, null);
    }

      




list_fragment_layout.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

</LinearLayout>

      

+2


source







All Articles