2012-05-25 10 views
5

मेरे एक्सएमएल:AutoCompleteTextView आइटम नीचे किसी भी बूंद नहीं दिखा रहा

<AutoCompleteTextView 
     android:id="@+id/searchAutoCompleteTextView_feed" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:completionThreshold="2" 
     android:hint="@string/search" /> 

मेरी जावा कोड:

AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed); 
eT.addTextChangedListener(this); 
String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; 
ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa); 
eT.setAdapter(aAdapter); 

यह atall काम नहीं कर रहा .... मेरा मतलब है अपने बस एक EditTextView की तरह काम कर रहे। मैं कहाँ गलत हूँ ??

पूरा कोड:

public class FeedListViewActivity extends ListActivity implements TextWatcher{ 


    private AutoCompleteTextView eT; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.feed); 

     eT = (AutoCompleteTextView) findViewById(R.id.searchAutoCompleteTextView_feed); 
     eT.addTextChangedListener(this); 

        Thread thread = new Thread(null, loadMoreListItems); 
        thread.start(); 
    } 

    private Runnable returnRes = new Runnable() { 
     public void run() { 

      //code for other purposes 
     } 
    }; 

    private Runnable loadMoreListItems = new Runnable() { 
     public void run() { 
      getProductNames(); 

      // Done! now continue on the UI thread 
      runOnUiThread(returnRes); 
     } 
    }; 

    protected void getProductNames() { 

      String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; 

      ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(getApplicationContext(), 
        android.R.layout.simple_dropdown_item_1line, sa); 
      eT.setAdapter(aAdapter); 

    } 

    public void afterTextChanged(Editable s) { 
     // TODO Auto-generated method stub 

    } 

    public void beforeTextChanged(CharSequence s, int start, int count, 
      int after) { 
     // TODO Auto-generated method stub 

    } 

    public void onTextChanged(CharSequence s, int start, int before, int count) { 
     // TODO Auto-generated method stub 

    } 
} 
+0

हर तरह से काम नहीं कर रहा है? जांचने के लिए आपने कितने अक्षर टाइप किए हैं? –

+4

आपने थ्रेसहोल्ड को 2 के रूप में उपयोग किया था, इसलिए 2 अक्षर – Venky

+0

टाइप करने के बाद यह आग लग जाएगी, हाँ, मैं हमेशा 2 से अधिक टाइप कर रहा हूं ... यह कोई ड्रॉप डाउन आइटम नहीं दिखा रहा है – Housefly

उत्तर

11

मैं सिर्फ अपने अन्य प्रश्न देखा इस एक को देखने से पहले काम कर रहे। मैं कुछ समय के लिए स्वतः पूर्ण के साथ संघर्ष कर रहा था और मैं लगभग सभी कीवर्ड डाउनलोड करने के आपके नए कार्यान्वयन में वापस आ गया जब तक कि मैं इसे काम करने के लिए अंत में नहीं मिला। मैंने क्या किया;

//In the onCreate 
//The suggestArray is just a static array with a few keywords 
this.suggestAdapter = new ArrayAdapter<String>(this, this.suggestionsView, suggestArray); 
//The setNotifyOnChange informs all views attached to the adapter to update themselves 
//if the adapter is changed 
this.suggestAdapter.setNotifyOnChange(true); 

मेरी textwatcher के onTextChanged विधि में, मैं एक asynctask

//suggestsThread is an AsyncTask object 
suggestsThread.cancel(true); 
suggestsThread = new WertAgentThread(); 
suggestsThread.execute(s.toString()); 

का उपयोग कर AsyncTask के onPostExecute में मैं तो autocompletetextview

//suggestions is the result of the http request with the suggestions 
this.suggestAdapter = new ArrayAdapter<String>(this, R.layout.suggestions, suggestions); 
this.suggestions.setAdapter(this.suggestAdapter); 
//notifydatasetchanged forces the dropdown to be shown. 
this.suggestAdapter.notifyDataSetChanged(); 

अधिक जानकारी के लिए setNotifyOnChange और notifyDataSetChanged देखें अद्यतन पता चलता है मिल

+8

बदलकर जांचने की आवश्यकता है ऐसा लगता है कि आपने NotifyDataSetChanged() विधि की अवधारणा को पूरी तरह से समझ नहीं लिया है। आप अपने onPostExecute विधि में ArrayAdapter का एक नया उदाहरण बना रहे हैं, और इसे एडाप्टर के रूप में सेट करें। NotifyDataSetChanged() विधि कॉल आपके उदाहरण में बेकार है। –

0
AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed); 
// eT.addTextChangedListener(this); 
    String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; 
    ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa); 
    eT.setAdapter(aAdapter); 

इसकी सिर्फ et.addtext लाइन पर टिप्पणी ...

+0

काम किया हाँ मैंने कोशिश की .... यह मेरे लिए काम नहीं किया – Housefly

+0

यह मेरे एंड्रॉइड 2.3.1 संस्करण में पूरी तरह से काम कर रहा है .. – jigspatel

+0

संस्करण के लिए संस्करण मायने रखता है autocompletetextview ??? ... मुझे पता है ... मैं कुछ कम एपीआई हूं ... – Housefly

1

यह मेरी परियोजना से एक स्निपेट है। मुझे लगता है कि आपको सेवाओं से डेटा प्राप्त करने के बाद आपको यह करना है:

  1. अपने पिछले डेटा को साफ़ करें।
  2. पिछले एडाप्टर मान साफ़ करें।
  3. फिर जोड़ें() या addAll() विधि का उपयोग कर डेटा की अपनी सूची में मूल्य जोड़ें।
  4. एडाप्टर पर NotifyDataSetChanged() को कॉल करके परिवर्तित डेटा को सूचित करें।

    @Override 
    public void onGetPatient(List<PatientSearchModel> patientSearchModelList) { 
    
    //here we got the raw data traverse it to get the filtered names data for the suggestions 
    
    stringArrayListPatients.clear(); 
    stringArrayAdapterPatient.clear(); 
    for (PatientSearchModel patientSearchModel:patientSearchModelList){ 
    
        if (patientSearchModel.getFullName()!=null){ 
    
         stringArrayListPatients.add(patientSearchModel.getFullName()); 
    
        } 
    
    } 
    
    //update the array adapter for patient search 
    stringArrayAdapterPatient.addAll(stringArrayListPatients); 
    stringArrayAdapterPatient.notifyDataSetChanged(); 
    

    }

लेकिन यह सब से पहले सुनिश्चित करें कि आप इस प्रकार अगर यह मत करो स्वत: पूर्ण TextView के लिए एडाप्टर संलग्न करें:

ArrayAdapter<String> stringArrayAdapterPatient= new ArrayAdapter<String>(getActivity(),android.support.v7.appcompat.R.layout.select_dialog_item_material,stringArrayListPatients); 

completeTextViewPatient.setAdapter(stringArrayAdapterPatient); 
संबंधित मुद्दे