Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChipsInputLayout not showing suggestion nor chips #30

Open
amethystant opened this issue May 7, 2018 · 1 comment
Open

ChipsInputLayout not showing suggestion nor chips #30

amethystant opened this issue May 7, 2018 · 1 comment

Comments

@amethystant
Copy link

Hello,
I'm trying to use the ChipsInputLayout in my project and I'm struggling with it. The problem is that the widgets doesn't show any options, although I have set a proper filterable list. It doesn't even show any chips that I add manually. I suppose it's not really a bug, but probably I'm doing something wrong. Anyway, I'd be thankful if the author of the library can have a look at it.
I inherited the Chip class like this:

public class ContactChip extends Chip {

    private String name;
    private String number;

    public ContactChip(@NonNull String name, @NonNull String number) {
        this.name = name;
        this.number = number;
    }

    @Override
    public Object getId() {
        return number;
    }

    @NonNull
    @Override
    public String getTitle() {
        return name;
    }

    @Override
    public String getSubtitle() {
        return number;
    }

    @Override
    public Uri getAvatarUri() {
        return null;
    }

    @Override
    public Drawable getAvatarDrawable() {
        return MyApplication.getInstance().getDrawable(R.drawable.ic_people_black_24dp);//todo replace
    }
}

Then I added the widgets to my fragment's xml like this:

<com.tylersuehr.chips.ChipsInputLayout
                android:id="@+id/chips_input_recipients"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginStart="@dimen/margin_start_message_editor_column_2"
                app:chipsList="@{viewmodel.chips}"
                app:allowCustomChips="true"
                app:chip_showDetails="true"
                android:hint="@string/hint_chips_input_recipients" />

(Note that the chipsList attribute is just a custom attribute for Android Data Binding, but I already tried to delete it, the widget didn't work either.)

And then I have this method, which is called in onCreateView() of the fragment's class:

private void initChipsInput(@NonNull final ChipsInputLayout chipsInput) {

        ArrayList<Message.Recipient> contacts = ContactsDataSource.getInstance().getContacts();
        ArrayList<Chip> chips = new ArrayList<>();
        for (int i = 0; i < contacts.size(); i++) {
            Message.Recipient contact = contacts.get(i);
            chips.add(new ContactChip(contact.name, contact.number));
        }

        chipsInput.setFilterableChipList(chips);
        chipsInput.addSelectionObserver(new ChipDataSource.SelectionObserver() {
            @Override
            public void onChipSelected(Chip chip) { updateVM(); }

            @Override
            public void onChipDeselected(Chip chip) { updateVM(); }

            void updateVM() {
                if(viewModel != null) {
                    viewModel.chips.clear();
                    viewModel.chips.addAll(chipsInput.getSelectedChips());
                }
            }
        });
    }

Again, it didn't work even when I deleted the selectionObserver. The mechanism of getting the list of contacts is working correctly, I tried to run it in the debugger and the list passed to setFilterableChipsList() is OK, it contains 64 items with all the names and phone numbers of my contacts. And still it doesn't show any list of options when I type anything. I also tried to manually add some chips by calling addSelectedChip(), and it wasn't shown. It's just behaving like a normal EditText... Thanks for any help.

@amethystant
Copy link
Author

amethystant commented May 11, 2018

UPDATE: I did some debugging and found out that FilterableRecyclerView.fadeIn() is called when it should be and it's actually setting itself to visible. I have even checked the LayoutParams it creates in that method, and the top and bottom margins are OK. But I also found out that FilterableChipsAdapter.onCreateViewHolder() is never called. It's weird, but now I believe that this is a bug, not my fault. I can send you my whole project to look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant