Search code examples
androidandroid-arrayadapterautocompletetextview

DisplayListCanvas is started on unbinded RenderNode (without mOwningView)


I'm trying to populate AutoCompleteTextView using my custom ArrayAdapter. I think it works fine with adding display values. The only problem is that no dropdown is being displayed. Does anybody know how to have this dropdown visible? Every time I should see the dropdown I can see log message saying:

DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)

My adapter code:

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

}

My MainActivity code:

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

                }
            });
        }
    });

}

Solution

  • Modify your adapter which has the filtering logic within it as shown below.

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

    Note: import android.widget.Filter; Hope this helps!!!