سؤال

I can't seem to find solutions to this supposedly simple problem /bug, so here is it:

A ListFragment of type (android.R.layout.simple_list_item_checked ) which when clicked, will load other fragments and do other work.

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


Photo 1: Normal Condition

1-normal


Photo 2: List Scrolled down - Everything still working fine (Lamborghini is out of view) 2-normal-end


Photo 3 : However when i selected Porsche and scrolled down, the "Mustang" text got corrupted

4-error1


Photo 4 : So is "Lamborghini" when scrolled back up after some random clicking

5-error2


Codes that i've used to create the listview is fairly straightforward:

 @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've tried calling notifyDataSetChanged() in the end of onListItemClick() hoping that it would refresh the list, but the problem still persist. Any possible solutions to this? Thanks!

PS: I'm running it on Galaxy Tab 10.1, Honeycomb 3.1 with support-library-v4. Could it possibly be a bug on this build?

هل كانت مفيدة؟

المحلول

I've solved the problem by overriding onCreateView and passing a layout file which contains a 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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top