टाइप किए गए एकल वर्ण के लिए नहीं दिख रहे हैं मैं स्कैला में लिखे गए एंड्रॉइड एप्लिकेशन पर काम कर रहा हूं जो द्वारा ओवरराइड किए गए एक्शन बार के अंदर android.support.v7.widget.SearchView
का उपयोग करता है।खोज दृश्य संकेत
ऐप में, मुझे उस SearchView
के लिए खोज सुझाव सक्षम करने की आवश्यकता है। इसलिए, हर बार जब मैं एक क्वेरी परिवर्तन का पता लगाता हूं, तो मैं यह देखने के लिए जांच करता हूं कि सुझावों को अपडेट करने की आवश्यकता है (नीचे कोड)। यदि सुझावों को अपडेट करने की आवश्यकता है तो बैकएंड को कॉल किया जाता है और android.database.MatrixCursor
बनाया जाता है जिसमें खोज सुझाव होते हैं और SearchView
के सुझाव एडाप्टर (नीचे कोड) पर सेट होते हैं।
समस्या यह है कि मेरे साथ यह समस्या यह है कि एकल वर्ण टाइप करते समय खोज संकेत दिखाई नहीं देंगे। खोज बॉक्स में दो या दो से अधिक अक्षर टाइप करना पूरी तरह से काम करता है।
मैं अपने एक्सएमएल config में 0
और 1
करने के लिए android:searchSuggestThreshold
सेट के साथ की कोशिश की है और मैं एक ही परिणाम प्राप्त (जैसे कि विकल्प अनदेखा किया जा रहा): खोज संकेत एकाधिक इनपुट पात्रों के लिए दिखा रहा है, लेकिन एक भी चरित्र के लिए प्रदर्शित नहीं।
क्या मुझे SearchView
की कॉन्फ़िगरेशन/प्रारंभिकरण में कुछ याद आ रही है? android:searchSuggestThreshold
के अलावा किसी अन्य विकल्प की तरह मैं सेट कर सकता हूं? मैंने पिछले कुछ घंटों को वैकल्पिक विकल्पों की तलाश में बिताया है लेकिन कोई भी नहीं मिला।
सम्भावित समाधान है कि मैं देख रहा हूँ SearchView
के इनपुट का समर्थन और 1 को इसके लिए सीमा की स्थापना AutoCompleteTextView
हो रही हैं, लेकिन यह AutoCompleteTextView
के रूप में एक बदसूरत (हैक-ish) समाधान SearchView
द्वारा उजागर नहीं कर रहा है एपीआई।
क्या कोई इस के लिए एक सुरुचिपूर्ण समाधान जानता है?
धन्यवाद!
का पता लगा रहा खोज पद परिवर्तन:
//this gets called whenever something is changed in the search box. "s" contains the entire search term typed in the search box
def onQueryTextChange(s: String): Boolean = {
//this checks to see if a call should be made to the backend to update suggestions
SearchSuggestionController.query(s)
//return false as we're not consuming the event
false
}
अद्यतन कर रहा है खोज सुझावों को:
def updateSuggestions(suggestions: Array[String]): Unit = {
val cursor = new MatrixCursor(Array(BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1), suggestions.length)
for{
i <- suggestions.indices
s = suggestions(i)
} cursor.addRow(Array[AnyRef](i.toString, s))
getActivity.runOnUiThread(() => {
searchSuggestionAdapter.changeCursor(cursor)
searchSuggestionAdapter.notifyDataSetChanged()
})
}
मेनू SearchView प्रारंभ:
override def onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) = {
inflater.inflate(R.menu.menu_products, menu)
val searchManager = getActivity.getSystemService(Context.SEARCH_SERVICE).asInstanceOf[SearchManager]
val actionItem = menu.findItem(R.id.action_search)
searchView = MenuItemCompat.getActionView(actionItem).asInstanceOf[SearchView]
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity.getComponentName))
searchView.setSubmitButtonEnabled(false)
SearchSuggestionController.onSuggestionsProvided_=(updateSuggestions)
searchView setSuggestionsAdapter searchSuggestionAdapter
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//...
//change listener for detecting search changes presented above
//...
}
//...
//initialise other components
//...
}
खोजने-config:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/actionbar_products_search_hint"
android:searchSuggestThreshold="0"
android:searchSuggestSelection=" ?"/>
ड्रॉपडाउन प्राप्त करना वही है जो मैं टालने की कोशिश कर रहा था। जब टेक्स्ट लम्बाई 1 होती है तो 'showDropDown' को कॉल करना' सेट थ्रेसहोल्ड (1) 'जैसा ही होता है। –