输入短划线键后,AutocompleteTextView消失(图像)

时间:2016-04-28 14:31:57

标签: android listview searchview autocompletetextview

我在数据库中存储了复合名称/单词,例如 good-for-nothing ,如下图所示。我在ActionBar中实现了SearchView。它工作得很好。除非我在Android键盘上按/键 - (hiphen / minus符号),否则会错过该词的建议。我该如何解决这个问题?

enter image description here

但是当我将短信与短划线( - )

分开时,屏幕上会显示

enter image description here

或以这种方式输入(_)

enter image description here

Searchable.xml

<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/search_label"
        android:hint="@string/search_hint"
        android:searchSettingsDescription="@string/settings_description"
        android:searchSuggestAuthority="com.br.dict.searchabledict.DictionaryProvider"
        android:searchSuggestIntentAction="android.intent.action.VIEW"
        android:searchSuggestIntentData="content://com.br.dict.searchabledict.DictionaryProvider/dictionary"
        android:searchSuggestSelection=" ?"
        android:searchSuggestThreshold="0"
        android:ems="14"
        android:includeInGlobalSearch="true"
        >
 </searchable>

menu.xml文件

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

活动

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true);
        searchView.setSubmitButtonEnabled(true);
        searchView.setBackgroundResource(R.drawable.shape4);

        int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
        searchPlate.setTextColor(getResources().getColor(R.color.branco));
        searchPlate.setTextSize(17);
        searchPlate.setHint("Search");
        int searchTextId = searchPlate.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView searchText = (TextView) searchPlate.findViewById(searchTextId);

        if (searchText != null) {
            searchText.setTextColor(Color.WHITE);
            searchText.setHintTextColor(Color.WHITE);

            int searchEditTextId = getResources().getIdentifier("android:id/search_src_text", null, null);

            final AutoCompleteTextView searchEditText = (AutoCompleteTextView) searchView.findViewById(searchEditTextId);
            searchEditText.setTextColor(Color.WHITE);
            searchEditText.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
            searchEditText.setDropDownBackgroundResource(R.drawable.shape4);
        }
    }
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.search:
            onSearchRequested();
            return true;
        default:
            return false;
        case android.R.id.home:
            MediaPlayer player = MediaPlayer.create(Dicionario.this, R.raw.click4);
            player.start();
            player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer player) {
                    player.release();
                }
            });
            super.onBackPressed();
            return true;
    }
}

0 个答案:

没有答案