2012-11-19 36 views
3

我想在AutoCompleteTextView的下拉建議列表的右側添加PgUp/PgDn按鈕。我使用上述佈局創建了自己的彈出窗口(佈局xml如下所示)。任何人都可以讓我知道如何用我自己的彈出窗口替換AutoCompleteTextView的下拉列表視圖?如何爲AutoCompleteTextView創建我自己的下拉視圖?

這是我想它的樣子:

<?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> 

回答

1

爲了得到這個簡單的做,我會建議你來設計佈局(帶兩個按鈕),並設置爲您AutoCompleteTextView如下:

android:completionHintView="@layout/your_custom_view" 

之後,可能自定義按鈕的單擊事件以執行所需的分頁操作。

+0

謝謝沃歌斯。用於單個建議項目的completionHintView或顯示建議列表的彈出窗口?我需要替換彈出窗口。我試圖在android:completionHintView中使用佈局(在我原來的quation中),但得到了NullPointerException。 – j1999

+0

NullPointerException是由其他人引起的。但下拉視圖仍然是一樣的。 – j1999

+0

也許您應該嘗試創建自定義視圖組(EditText + PopupWindow)來模擬此行爲 – waqaslam

0

使用AutocompleteTextView,設置高treshold 「setTreshold()」,並呼籲showDropDown()按鈕點擊

代碼:

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(); 
} 
}); 
相關問題