तो अगर आप एक SearchView उपयोग कर रहे हैं आप में परियोजना और सुझावों तुम वहाँ दो तरीकों
/**
* Called when the user submits the query. This could be due to a key press on the
* keyboard or due to pressing a submit button.
* The listener can override the standard behavior by returning true
* to indicate that it has handled the submit request. Otherwise return false to
* let the SearchView handle the submission by launching any associated intent.
*
* @param query the query text that is to be submitted
*
* @return true if the query has been handled by the listener, false to let the
* SearchView perform the default action.
*/
boolean onQueryTextSubmit(String query);
/**
* Called when the query text is changed by the user.
*
* @param newText the new content of the query text field.
*
* @return false if the SearchView should perform the default action of showing any
* suggestions if available, true if the action was handled by the listener.
*/
boolean onQueryTextChange(String newText);
लागू कर सकते हैं दिखाने के लिए आप प्रलेखन कैसे इन तरीकों काम से देख सकते हैं चाहता हूँ। तब तक जब तक उपयोगकर्ता टाइप कर रहे हैंQueryTextChange विधि को कॉल किया जाएगा और हर बार जब नया कीवर्ड दर्ज किया जाता है या हटा दिया जाता है तो इसे कॉल किया जाएगा।
इस विधि में आप सर्वर को सुझाव प्राप्त करने और उसे उपयोगकर्ता को देने के लिए कॉल कर सकते हैं।
अब यदि उपयोगकर्ता उदाहरण के लिए खोजना चाहता है। "सेब" इसलिए प्रत्येक कीवर्ड के लिए सर्वर को हिट करने का अर्थ नहीं होगा, जैसे कि "एप" के बाद "ए" के बाद "एपी" और उसके बाद
तो सर्वर को एक बार हिट करना बेहतर होगा उपयोगकर्ता सर्चव्यू में टाइपिंग बंद कर देता है जिसे आप हैंडलर का उपयोग करके संभाल सकते हैं और इस तरह कुछ चलाने योग्य हैं।
Handler mHandler;
String mQueryText;
@Override
public boolean onQueryTextChange(final String newText) {
mQueryText=newText;
//Make if invisible once you get the data.
mProgressBar.setVisibility(View.VISIBLE);
mHandler.removeCallbacks(mRunnable);
mHandler.postDelayed(mRunnable,200);
return true;
}
private Runnable mRunnable =new Runnable() {
@Override
public void run() {
//Hit server here.
}
};
जबकि आप सर्वर को मारकर डेटा प्राप्त कर सकते हैं तो आप प्रगति पट्टी या कुछ दिखा सकते हैं।
आप एडिटटेक्स्ट https://developer.android.com/reference/android/widget/EditText.html के साथ एक ही तर्क लागू कर सकते हैं। उम्मीद है कि यह मदद करता है।
स्रोत
2017-07-25 13:27:25