Buggy ListView makes me sad

风流意气都作罢 提交于 2019-11-27 06:53:39

It sounds like ListViews aren't able to handle EditTexts well. I've done some research and the consensus seems to be "don't do that." So what I've resorted to is creating a simple layout file which is a ScrollView with a LinearLayout inside. In my onCreate method, I inflate the View I was using for my list item and add it to the LinearLayout. I'm also adding the View to an ArrayList so I can save the data in each View later on.

Does this sound reasonable?

Sreekanth Karumanaghat

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

android:windowSoftInputMode="adjustPan"

Example...

<activity android:name=".mapview.AddParkingLotActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/>

I was having the same problem. My EditText inside of LisView was losing focus when the keyboard appears, so on getView from the ListView item I put

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

And this work for me.

These two steps resolved a similar issue I had (EditText on a row within ListView + funny keyboard behavior).

  1. Add android:windowSoftInputMode="adjustPan" attribute into AndroidManifest.xml file on the activity where the ListView is presented.
  2. Add android:descendantFocusability="afterDescendants" attribute onto the ListView itself.

This is the actual 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 Samsung Galaxy S3 and it works fine with Samsung as well as SwiftKey keyboards.

ashish

i have some issue i solved just commenting this line

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!