AutoCompleteTextView not showing any drop down items

前端 未结 5 1574
[愿得一人]
[愿得一人] 2021-01-17 17:31

My XML:



        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 18:14

    this is a snippet from my project. I think after you got data from services all you have to do is to:

    1. clear your previous data.
    2. clear the previous adapter values.
    3. then add values to your list of data using add() or addAll() method.
    4. notify the data changed by calling notifyDataSetChanged() on adapter.

      @Override
      public void onGetPatient(List 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();
      

      }

    but before all this make sure you have attached the adapter to the auto complete textview if don't do it as follows:

    ArrayAdapter stringArrayAdapterPatient= new ArrayAdapter(getActivity(),android.support.v7.appcompat.R.layout.select_dialog_item_material,stringArrayListPatients);
    
    completeTextViewPatient.setAdapter(stringArrayAdapterPatient);
    

提交回复
热议问题