Buggy ListView makes me sad

I have a ListView where I defined the layout of each element in a separate XML file. In this file, I have included RatingBar and EditText .

I programmatically created 7-8 items in this ListView . When I scroll through them, it seems like it's pretty buggy. Here are some examples:

  • If I set the focus on EditText in the first row, and then scroll down the ListView , random EditTexts from other rows will have focus. It looks like the next EditText after the focused one disappears, gets the focus. Perhaps this is intentional, but as a user, it seems very strange.

  • If I set focus on EditText , get a virtual keyboard, type something and click the Finish button on my virtual keyboard, EditText will be empty as soon as the virtual keyboard disappears.

  • Sometimes, when I click EditText , I get a virtual keyboard and start typing letters, the letters disappear as soon as I type them.

  • When I click on EditText , the virtual keyboard shows itself, but EditText loses focus, and I need to click EditText again.

  • Even if I set the RatingBar to focusable="false" , if I move my scroll wheel, it still captures the focus.

One of my problems is that all the visible elements of the list get redrawn when I type in the character on the virtual keyboard (and since the EditText set to some data that is empty, it is cleared. I don’t understand why Android decides to redraw the list each time the character is entered.

Here is the XML that I use to draw them. These are white bubbles with a gray border and some text, RatingBar and EditText inside:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="10dip" android:paddingBottom="10dip" android:paddingLeft="15dip" android:paddingRight="15dip" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="2dip" android:background="@drawable/shape_outer"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="2dip" android:background="@drawable/shape_inner"> <TextView android:id="@+id/rating_category" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/dark_gray" android:textStyle="bold" android:layout_marginBottom="10dip" /> <RatingBar android:id="@+id/rating_rating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5" android:rating="0" android:stepSize="1" android:focusable="false" android:clickable="false" /> <EditText android:id="@+id/rating_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_column="1" android:padding="6dip" android:textColor="#000000" android:gravity="left|top" android:lines="3" android:hint="Comment" android:imeOptions="actionDone" /> </LinearLayout> </LinearLayout> </LinearLayout> 
+32
android listview listviewitem virtual-keyboard
Aug 12 '10 at 14:29
source share
5 answers

It seems that ListViews cannot handle EditTexts well. I did some research, and the consensus seems to be "don't do this." So I resorted to creating a simple layout file, which is a ScrollView with LinearLayout inside. In my onCreate method, I inflate the view I used for my list item and add it to LinearLayout. I also add View to ArrayList to save data in each view later.

Does that sound reasonable?

+19
Aug 12 '10 at 16:29
source share

Well, add this to your activity in the manifest ...

 android:windowSoftInputMode="adjustPan" 

Example...

 <activity android:name=".mapview.AddParkingLotActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/> 
+5
Jun 29 '12 at 6:29
source share

I had the same problem. My EditText inside LisView lost focus when the keyboard appeared, so on the getView from the ListView element I put

 final EditText editInput = (EditText)convertView.findViewById(R.id.edit_input); editInput.requestFocusFromTouch(); 

And this work is for me.

+4
Dec 08 '11 at 13:17
source share

These two steps solved a similar problem (EditText in a row in ListView + funny keyboard behavior).

  • Add the android attribute : windowSoftInputMode = "adjustPan" to the AndroidManifest.xml file in action where the ListView is presented.
  • Add android: descendantFocusability = "afterDescendants" to the ListView.

That's an example:

AndroidManifest.xml

  <activity android:name=".SubscriptionListActivity" android:windowSoftInputMode="adjustPan" android:label="@string/title_activity_subscriptions" > </activity> 

layout.xml file

  <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="afterDescendants" android:id="@+id/subscriptionList" /> 

I tested it on a Samsung Galaxy S3 and it works great with Samsung as well as with SwiftKey keyboards.

+3
Feb 17 '15 at 14:30
source share

I have a problem that I decided to just comment on this line

 this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
0
Aug 4 '14 at 7:21
source share



All Articles