开发者

Android autocomplete and soft keyboard

I followed the AutoCompleteTextView tutorial exactly. The layout gets wrong when a soft keyboard is involved.

Android autocomplete and soft keyboard

After tapping inside the dropdown (to select or scroll), the layout is broken:

Android autocomplete and soft keyboard

I tried various combinations of attributes on the AutoCompleteTextView but none seems to work. I also tried setting windowSoftInputMode. The dropdown always pops up above the textbox, and stays there forever.

In landscape orientation, the layout is OK:

Android autocomplete and soft keyboard

Is the standard autocomplete useless? Should I use a different one / write my own?

The code I used is the following:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:padding="5dp">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Country" />
    <AutoCompleteTextView android:id="@+id/autocomplete_country"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"/>
</LinearLayout>

MainActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AutoCompleteTextView textView = (AutoCompleteTextView)  findViewById(R.i开发者_StackOverflow社区d.autocomplete_country);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
    textView.setAdapter(adapter);
}


Instead of using AutoCompleteTextView, I used EditText and a ListView as shown here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜