2016-03-09 15 views
7

Sto tentando di popolare AutoCompleteTextView utilizzando la mia personalizzata ArrayAdapter. Penso che funzioni bene con l'aggiunta di valori di visualizzazione. L'unico problema è che non viene visualizzato alcun menu a discesa. Qualcuno sa come avere questo dropdown visibile? Ogni volta che dovrebbe vedere la discesa posso vedere log dei messaggi dicendo:DisplayListCanvas viene avviato su RenderNode non vincolato (senza mOwningView)

DisplayListCanvas: DisplayListCanvas è stato avviato sul RenderNode unbinded (senza mOwningView)

Il mio codice adattatore:

public class UserSearchAdapter extends ArrayAdapter<Profile> { 

    Context context; 
    ArrayList profiles; 


    public UserSearchAdapter(Context context, int resource, ArrayList<Profile> objects) { 
     super(context, resource, objects); 
     this.context = context; 
     this.profiles = objects; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      convertView = LayoutInflater.from(this.getContext()) 
        .inflate(R.layout.single_user_item, parent, false); 
     } 

     Profile profile = (Profile) profiles.get(position); 

     TextView text = (TextView) convertView.findViewById(R.id.single_user_name_text); 
     text.setText(profile.getDisplayName()); 

     return convertView; 
    } 

} 

Il mio codice MainActivity:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_member_supervisor); 
    activity = MemberSupervisorActivity.this; 

    Firebase.setAndroidContext(this); 

    autoCompleteUser = (AutoCompleteTextView) findViewById(R.id.auto_members); 

    profiles = new ArrayList<>(); 

    members = new UserSearchAdapter(activity, R.layout.single_user_item, profiles); 

    autoCompleteUser.setAdapter(members); 
    autoCompleteUser.setThreshold(1); 

    autoCompleteUser.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      final Query auto = new Firebase(Constants.FIREBASE_USER_PROFILE).orderByChild("displayName").startAt(autoCompleteUser.getText().toString()).endAt(autoCompleteUser.getText().toString() + "~"); 
      auto.addListenerForSingleValueEvent(new ValueEventListener() { 
       @Override 
       public void onDataChange(DataSnapshot dataSnapshot) { 
        profiles.clear(); 
        Log.d("entered", autoCompleteUser.getText().toString()); 
        for (DataSnapshot data : dataSnapshot.getChildren()) { 
         Profile profile = data.getValue(Profile.class); 
         profiles.add(profile); 
         Log.d("results", profile.getDisplayName()); 
        } 
        members.notifyDataSetChanged(); 
       } 

       @Override 
       public void onCancelled(FirebaseError firebaseError) { 

       } 
      }); 
     } 
    }); 

} 

risposta

1

Modificare l'adattatore che ha la logica di filtraggio al suo interno come mostrato di seguito.

public class UserSearchAdapter extends ArrayAdapter<Profile> { 

    Context context; 
    ArrayList profiles; 
    ArrayList<Profile> suggestions, tempItems; 

    public UserSearchAdapter(Context context, int resource, ArrayList<Profile> objects) { 
     super(context, resource, objects); 
     this.context = context; 
     this.profiles = objects; 
     this.suggestions=new ArrayList(); 
     tempItems = new ArrayList(Profile); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      convertView = LayoutInflater.from(this.getContext()) 
        .inflate(R.layout.single_user_item, parent, false); 
     } 

     Profile profile = (Profile) profiles.get(position); 

     TextView text = (TextView) convertView.findViewById(R.id.single_user_name_text); 
     text.setText(profile.getDisplayName()); 

     return convertView; 
    } 

    @Override 
    public Filter getFilter() { 
     return nameFilter; 
    } 

    /** 
    * Custom Filter implementation for custom suggestions we provide. 
    */ 
    Filter nameFilter = new Filter() { 
     @Override 
     public CharSequence convertResultToString(Object resultValue) { 
      String str = ((Profile) resultValue).getName(); 
      return str; 
     } 

     @Override 
     protected FilterResults performFiltering(CharSequence constraint) { 
      if (constraint != null) { 
       suggestions.clear(); 
       for (Profile profile : tempItems) { 
        if (profile.getDisplayName().toLowerCase().contains(constraint.toString().toLowerCase())) { 
         suggestions.add(profile); 
        } 
       } 
       FilterResults filterResults = new FilterResults(); 
       filterResults.values = suggestions; 
       filterResults.count = suggestions.size(); 
       return filterResults; 
      } else { 
       return new FilterResults(); 
      } 
     } 

     @Override 
     protected void publishResults(CharSequence constraint, FilterResults results) { 
      List<Profile> filterList = (ArrayList<Profile>) results.values; 
      if (results != null && results.count > 0) { 
       clear(); 
       for (Profile profile : filterList) { 
        add(profile); 
        notifyDataSetChanged(); 
       } 
      } 
     } 
    }; 
} 

Nota: import android.widget.Filter; Spero che questo aiuti !!!

+0

Quindi sto eseguendo anche l'avviso "DisplayListCanvas ...", e questo non è solo il risultato migliore, ma uno dei risultati SOLO. Mi sto chiedendo se puoi aiutare – Benjamin

Problemi correlati