gpt4 book ai didi

android - 在操作栏中获取搜索 View 的下拉列表

转载 作者:行者123 更新时间:2023-11-30 01:52:53 25 4
gpt4 key购买 nike

你们能给我建议吗?如何编辑此搜索 View ,以显示下拉列表,就像在 autoCompleteTextView 中一样?需要它来提供数学项目,接下来是 onClick

 ...
final MenuItem searchItem = menu.findItem(R.id.search);
setupSearchView(searchItem);
...

private void setupSearchView(MenuItem searchItem) {
mSearchView = (SearchView) searchItem.getActionView();
mSearchView.setQueryHint(getString(R.string.product_id));
mSearchView.setQuery(mSearchQuery, false);
mSearchView.setIconified(!mExpandSearch);
final int searchIconResId = getResources().getIdentifier("android:id/search_button", null, null);
final ImageView searchIcon = (ImageView) mSearchView.findViewById(searchIconResId);
searchIcon.setImageResource(R.drawable.ic_action_search); //
...

xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/search"
android:showAsAction="always"
android:icon="@drawable/ic_action_search"
android:title="@string/search"
android:actionViewClass="android.widget.SearchView" />

</menu>

最佳答案

您可以使用 AutoCompleteTextView 代替 SearchView

<AutoCompleteTextView
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionSearch"
android:inputType="textAutoComplete|textAutoCorrect"
android:textColor="#FFFFFF" >

<requestFocus />
</AutoCompleteTextView>

并在 Activity 中

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, autocompletelistvalues);
AutoCompleteTextView textView = (AutoCompleteTextView) v
.findViewById(R.id.editText1);
textView.setAdapter(adapter);

包含这个以动态过滤

 textView.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, ....){
//update your List based on CharSequnce entered
textView.setAdapter(filteredadapter);
notifyDataSetChanged();
}
});

关于android - 在操作栏中获取搜索 View 的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32739158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com