Closed elod91 closed 8 years ago
@elod91 can you please also show the source of this item, i assume that you do not correctly handle the selected
state within the bindView
method
package net.reea.shnapit.views;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.mikepenz.materialdrawer.model.BasePrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.utils.ViewHolderFactory;
import net.reea.shnapit.R;
public class DrawerItem extends BasePrimaryDrawerItem<DrawerItem> {
public static final String TYPE = "DRAWER_ITEM";
private String title, badge;
public DrawerItem withTitle(String title) {
this.title = title;
return this;
}
public DrawerItem withBadge(String badge) {
this.badge = badge;
return this;
}
@Override
public ViewHolderFactory getFactory() {
return new ItemFactory();
}
@Override
public String getType() {
return TYPE;
}
@Override
public int getLayoutRes() {
return R.layout.drawer_menu_item;
}
@Override
public void bindView(RecyclerView.ViewHolder holder) {
ViewHolder viewHolder = (ViewHolder) holder;
if (title != null)
viewHolder.title.setText(title);
if (badge == null) {
viewHolder.badge.setVisibility(View.GONE);
return;
}
viewHolder.badge.setText(badge);
}
public static class ItemFactory implements ViewHolderFactory<ViewHolder> {
public ViewHolder factory(View v) {
return new ViewHolder(v);
}
}
private static class ViewHolder extends BaseViewHolder {
private TextView title, badge;
public ViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.drawer_menu_title);
badge = (TextView) view.findViewById(R.id.drawer_menu_badge);
}
}
}
You have to add the following:
//set the item selected if it is
viewHolder.itemView.setSelected(isSelected());
this makes sure the state of the view is correctly set depending on the item
(in v5.0.0 this will be handled be the underlaying FastAdapter)
Thanks, it works.
Hello, I'm quite new to android developing and I very appreaciate what you have done here. I started writing my app in Kotlin and I was wondering how to write simple, custom item in my Drawer.
I have a problem with creating CustomItem class. Could you please help me with that?
Hey,
I've managed to create a custom drawer item, with a custom layout resource. In this layout there's a TextView with a selector as textColor. My problem is that the TextView remains selected after clicking on another drawer item.
Here's my menu item layout:
And as textColor for the drawer_menu_title the following selector is set: