panda
panda

Reputation: 1344

listview gets wrong display order

I have a ListView to display category items, below this, I have a control menu writen in a LinerLayout, and, also an EditText and go Button at the top of this app.

Everything is fine at the first running time. however, when I click the EditText for input, the menu bar is pulled up since the keyboard appear. Now, the order of the ListView has been changed.

example: at beginning: 1 Meeting 2 Event 3 Schedule 4 Reminder Later keyboard shows and everything pulled up: 1 Schedule 2 Reminder 3 Meeting 4 Event.

I also find that this problem will only happen when there is no enough space to keep showing the whole ListView.

I can't solve this problem after I searched for long time on the internet.

This is my layout and my List Apdater

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout ...>
        <ListView
            android:id="@+id/items"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/widget53"/>

        <LinearLayout
            android:id="@+id/widget39"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" >

            <ImageButton ../>

            <ImageButton ../>

            <ImageButton ../>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/widget53"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" >

            <Button ../>

            <EditText .. />
        </LinearLayout>
    </RelativeLayout>
//Write item on the screen
    lv = (ListView)findViewById(R.id.items);
            lv.setAdapter(indexadapter.getAdapter());
            lv.setTextFilterEnabled(true);
            lv.setOnItemClickListener(ItemClick);
//My list Adapter generate rows base on mData from database
    CategoryHolder CategoryHolder = null;
        if (convertView == null) {
            //getting view format
            CategoryHolder = new CategoryHolder();
            convertView = mInflater.inflate(R.layout.categoryshow, null);
            CategoryHolder.category=(TextView)convertView.findViewById(R.id.indexcategory);
        //setting tag for reuse;
            convertView.setTag(CategoryHolder);
        //setting text for each item;
        CategoryHolder.category.setText((String)mData.get(position).get("CATEGORY"));
        }else{
            CategoryHolder = (CategoryHolder)convertView.getTag();
        }

Upvotes: 1

Views: 639

Answers (2)

timoschloesser
timoschloesser

Reputation: 2802

When you use the convertView of the getView() method in your listadapter, you need to set the text for every view again. To fully understand how listviews are working and how the views are recycled you should watch these video form the google I/O 2010 http://www.google.com/events/io/2010/sessions/world-of-listview-android.html

Upvotes: 0

dldnh
dldnh

Reputation: 8951

in your AndroidManifest.xml file, in your <activity...> definition, include android:windowSoftInputMode="adjustPan" like so:

<activity
    android:name=".ClassName"
    android:windowSoftInputMode="adjustPan" >
    ...
</activity>

Upvotes: 2

Related Questions