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

Change layout by condition #29

Closed
danielpassos opened this issue Jul 31, 2017 · 3 comments
Closed

Change layout by condition #29

danielpassos opened this issue Jul 31, 2017 · 3 comments

Comments

@danielpassos
Copy link

danielpassos commented Jul 31, 2017

Is possible to I access my layout to change the text color like

if(item.price > 100) {
// change my TextViewColor
}

instead of use LayoutHandler with 2 differents layout:

LastAdapter(items, BR.something)
                .layout { item, position ->
                    if (items[position].price > 100) {
                        R.layout.item_red
                    } else {
                        R.layout.item_green
                    }
                }.into(something)
@danielpassos
Copy link
Author

I just realized I can do it on Type using onCreate/onRecycle.

Nevermind

@nitrico
Copy link
Owner

nitrico commented Jul 31, 2017

Hey, wait a second! :) Yes, it is possible, in a few different ways. I would recommend you this one:

<TextView
    ...
    android:textColor="@{item.price > 100 ? @color/red : @color/green}" />

so you can have only one type and only one layout. Simpler.

@danielpassos
Copy link
Author

Hey @nitrico Thanks for the tip,

It's not so simple, price was only an example, anyway... Type works for me and I have only one type and only one layout ;)

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

2 participants