2016-03-09 8 views
7

Özel ArrayAdapter'u kullanarak AutoCompleteTextView doldurmaya çalışıyorum. Ekran değerlerini ekleyerek güzel çalışıyor. Tek sorun, herhangi bir açılır pencere görüntülenmiyor olmasıdır. Bu açılır listenin nasıl görüneceğini herkes biliyor mu?DisplayListCanvas, bağımsız RenderNode üzerinde başlatıldı (mOwningView olmadan)

DisplayListCanvas: ben açılan görmelisiniz Her zaman dediğim mesajı log görebilirsiniz

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; 
    } 

} 
: DisplayListCanvas

Benim adaptör kodu (mOwningView olmadan) unbinded RenderNode üzerinde başlatılır

Benim AnaAktivite kodum:

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) { 

       } 
      }); 
     } 
    }); 

} 

cevap

1

Aşağıda gösterildiği gibi filtreleme mantığına sahip olan bağdaştırıcınızı değiştirin.

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(); 
       } 
      } 
     } 
    }; 
} 

Not: import android.widget.Filter; Umarım bu yardımcı olur!

+0

Yani "DisplayListCanvas ..." uyarısına da giriyorum ve bu sadece en iyi sonuç değil, SADECE sonuçlardan biri. Yardımcı olabilir misin merak ediyorum – Benjamin

İlgili konular