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

how to define viewTypes with conditions #69

Open
MahmoudMabrok opened this issue Aug 30, 2020 · 5 comments
Open

how to define viewTypes with conditions #69

MahmoudMabrok opened this issue Aug 30, 2020 · 5 comments
Labels
Q&A Questions and Answers

Comments

@MahmoudMabrok
Copy link
Contributor

now we can register viewTypes but README has no way to determine which viewType is created at spefici position i.e
how to make views has two types Head, Sub

  • Head with odd positions
  • Sub with even positions
@ibrahimyilmaz
Copy link
Owner

Hi @MahmoudMabrok,

Thank you for your question.

You specify this while you are defining your RecyclerViewHolder<T>.

You need to define HeadRecyclerViewHolder and SubRecyclerViewHolderfor your Head and Sub.

In the list, which you provide the adapter, you should do that mapping.

val list = listOf("abc", "xyz", "qwe", ...)

...
// mapper
val dataSource = list.mapIndexed{index, item ->
           if (index ÷ 2 == 0) Head(item) else Sub(item) 
}

adapter.submitList(dataSource)

In that way, you can test your mapper.

I hope everything is clear now.

Sincerely
Ibrahim

@MahmoudMabrok
Copy link
Contributor Author

it will more better if it added with register function

@ibrahimyilmaz
Copy link
Owner

Do you mean putting type in the register function?

@MahmoudMabrok
Copy link
Contributor Author

yes,or a way to determine type
add function like register but it return viewType
and with register we can select which type

i think it need brain storm to get right design

@ibrahimyilmaz
Copy link
Owner

Actually type is coming by RecyclerViewHolder. As it is reified Kiel could understand which type it is.

I appreciate your support. Any syntax alternatives are welcome.
also you may consider putting new syntax alternative under this issue #34.

@ibrahimyilmaz ibrahimyilmaz added the Q&A Questions and Answers label Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions and Answers
Projects
None yet
Development

No branches or pull requests

2 participants