I create a simple ListView
where each row is an EditText
. Here is my R.layout.item
:
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine">
</EditText>
Notice how the EditText
allows multi-line input through the android:inputType="textMultiLine"
flag. By means of an ArrayAdapter
I populate the ListView
with a number of rows such that the ListView
can be scrolled. In my case the items are 40. Here is my MainActivity.java
:
public class MainActivity extends ListActivity {
final int NUM_ITEMS = 40;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] items = new String[NUM_ITEMS];
for (int i = 0; i < NUM_ITEMS; i++) {
items[i] = Integer.toString(i);
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.item, items));
}
}
I scroll down to row 20 and start typing text, but when I reach the end of the line and the EditText
changes its size to accommodate for the second row, suddenly the ListView
automatically scrolls all the way to the top.
I consider the described behaviour a horrible user experience and I struggle to understand why it should be the default. The behaviour I look for is for the rows above to stay put and for the rows below to shift of the necessary amount to leave room for the expanded EditText
. How can I achieve it?
Some additional info, I run this code on the emulator against Android 4.2.2, the device is a 3.2" HVGA slider (ADP1). I've chosen that particular device to reproduce a bug experienced by a user.