j1999
j1999

Reputation: 91

How to create my own dropdown view for AutoCompleteTextView?

I'd like to add PgUp/PgDn button at right side of the drop down suggestion list of AutoCompleteTextView. I created my own popup window with the layout described above (the layout xml showed below). Could anyone let me know how to replace the drop down list view of AutoCompleteTextView with my own popup window?

Here is what I'd like it looks like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:weightSum="10">

    <ListView
        android:id="@+id/listView"
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:layout_weight="9"
        android:background="@drawable/frame">
    </ListView>
    <RelativeLayout android:id="@+id/pageUpDown" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent">
        <ImageButton android:id="@+id/pageUp" android:src="@drawable/pct_up_icon" android:background="@null"  android:layout_width="48dp" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:text="" android:layout_height="48dp"></ImageButton>
        <ImageButton android:id="@+id/pageDown" android:src="@drawable/pct_down_icon" android:background="@null" android:layout_width="48dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="" android:layout_height="48dp"></ImageButton>
    </RelativeLayout>

</LinearLayout>

Upvotes: 4

Views: 7510

Answers (3)

Chirag Nagpal
Chirag Nagpal

Reputation: 729

use AutocompleteTextView, set high treshold "setTreshold()" and call showDropDown() on button click

code:

String[] values = {
"abc_0", "def_0", "ghi_0",
"abc_1", "def_1", "ghi_1",
"abc_2", "def_2", "ghi_2",
"abc_3", "def_3", "ghi_3",
};

 final AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
 final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, values);
actv.setAdapter(adapter);
actv.setThreshold(256); // if not enough set Integer.MAX_VALUE
findViewById(R.id.button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
    CharSequence constraint = actv.getText();
    adapter.getFilter().filter(constraint);
    actv.showDropDown();
}
}); 

Upvotes: 0

waqaslam
waqaslam

Reputation: 68187

To get this done simply, I would recommend you to design your layout (with two buttons) and set to your AutoCompleteTextView as below:

android:completionHintView="@layout/your_custom_view"

Later, you may customize your buttons' click events to perform the desired paging actions.

Upvotes: 2

Lucas Arrefelt
Lucas Arrefelt

Reputation: 3929

I asked this question myself some time ago, and found a solution myself aswell. Check here:

Style on AutoCompleteTextView dropdown

Upvotes: 0

Related Questions