Android: Make AutoCompleteTextView dropdown wrap to 2 lines or more

前端 未结 2 1548
小鲜肉
小鲜肉 2021-02-02 16:05

I am writing an Android app that uses an AutoCompleteTextView just like the API example. The problem is that my text is too long and needs to wrap when the dropdown occurs. I

相关标签:
2条回答
  • 2021-02-02 16:50

    easy way :
    adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.two_line_list_item,android.R.id.text1,....);

    android.R.layout.two_line_list_item this is easy change.

    0 讨论(0)
  • 2021-02-02 16:55

    Wrap the TextView in a layout and use that for your ArrayAdapter

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView 
            android:id="@+id/item"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textSize="16sp"
            android:textColor="#000"    
            />
    
    </LinearLayout>
    

    And the new calls for the ArrayAdapter:

        AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
        ArrayAdapter<String> adapter  = new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.item, COUNTRIES);
        textView.setAdapter(adapter);
    
    0 讨论(0)
提交回复
热议问题