I am using MaterialDrawer (and also FastAdapter) to create left and right drawers in my app and currently I use a compact style account header in the right drawer (see the green area with user photo in the below screenshot).
However I need few more text fields there, so I would like to switch - and use a custom PrimaryDrawerItem (please see the magenta area in the below screenshot).
I have studied the guides listed at https://github.com/mikepenz/MaterialDrawer/blob/develop/FAQ/howto_modify_add_custom_draweritems.md and have tried creating such an item with an ImageView and two TextViews here:
public class RightDrawerItem extends AbstractDrawerItem<RightDrawerItem, RightDrawerItem.ViewHolder> {
public String photo;
public String given;
public String score;
@Override
public int getType() {
return R.id.right_drawer_item_id;
}
@Override
@LayoutRes
public int getLayoutRes() {
return R.layout.right_drawer_item;
}
@Override
public void bindView(ViewHolder vh, List<Object> payloads) {
super.bindView(vh, payloads);
Context ctx = vh.itemView.getContext();
if (ctx.getApplicationContext() instanceof SlovaApplication) {
SlovaApplication app = (SlovaApplication) ctx.getApplicationContext();
if (URLUtil.isHttpsUrl(photo)) {
app.getPicasso()
.load(photo)
.placeholder(R.drawable.account_gray)
.into(vh.mPhoto);
}
}
vh.mGiven.setText(given);
vh.mScore.setText(score);
//call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
onPostBindView(this, vh.itemView);
}
@Override
public ViewHolder getViewHolder(View v) {
return new ViewHolder(v);
}
public void setPhoto(String photo) {
this.photo = photo;
}
public void setGiven(String given) {
this.given = given;
}
public void setScore(String score) {
this.score = score;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
private ImageView mPhoto;
private TextView mGiven;
private TextView mScore;
private ViewHolder(View view) {
super(view);
view.setBackgroundColor(Color.MAGENTA);
mPhoto = view.findViewById(R.id.photo);
mGiven = view.findViewById(R.id.given);
mScore = view.findViewById(R.id.score);
}
}
}
My problem is that when I call
mRightDrawerItem.setPhoto(...);
mRightDrawerItem.setGiven(...);
mRightDrawerItem.setScore(...);
then the views my custom PrimaryDrawerItem are not updated, as you can see in the magenta area of the screenshot (pardon the non-english text):
Also, I am not quite sure what exactly is the vh.itemView
?
I have also asked my question in the Github issue 2349