-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Activity start and withOnDrawerItemClickListener clicked. #1908
Comments
You may be setting the drawer to open position 0 on launch, which is triggering the listener. If you need more help maybe post how you've added the drawer. |
|
Is that your actual implementation? You have a few instance where you've built the drawer and didn't use it, and you won't need to open then close the drawer immediately. On the top of your formatted code portion, you can see |
Thank you. I got it, but how I can set selection for each item when item clicked ? It not automation select anymore. ?? final Drawer result = new DrawerBuilder()
.withActivity(this)
.withAccountHeader(headerResult)
.withToolbar(toolbar)
.addDrawerItems(
item1,
item2,
item3,
item4,
item5,
item6,
item7,
item8
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
// do something with the clicked item :D
if(drawerItem.getIdentifier() ==1)
{
Intent intent = new Intent(getApplicationContext(), HandleMapsActivity.class);
getApplicationContext().startActivity(intent);
return true;
}
if(drawerItem.getIdentifier() == 2)
{
Intent intent = new Intent(getApplicationContext(), CreatedOrderActivity.class);
getApplicationContext().startActivity(intent);
return true;
}
return false;
}
})
.build();
item1.withBadge("19").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_create_new));
item2.withBadge("5").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_created));
item3.withBadge("5").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_tutorials));
item4.withBadge("19").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_your_profile));
item5.withBadge("5").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_about));
item6.withBadge("5").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_version));
item7.withBadge("19").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_settings));
item8.withBadge("5").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_green_900)).withIcon(getResources().getDrawable(R.drawable.ic_logout)); |
@trinhvanminh2009 return |
@mikepenz Thanks . I return true or return false always have a problem. After startActivity(intent) it always choose selection(item1). I'm using this class is abstract and others class extends from this class. I can't use |
I know when I startActivity(Intent) then new class will refresh this. That why it always selection(item1). Can you give me an idea to fix it ? |
@trinhvanminh2009 Typically, the drawer is attached to the activity and the inner contents are managed by fragments. Perhaps you should look at that rather than launching a new activity every time. If you do choose to stick with the activity, maybe pass the position index into the next activity and then set the drawer position to that value when it loads. Look up intent extras for that. Edit: I now see that a lot of the code you posted matches that of the sample app. Keep in mind that the purpose of that app is to showcase many drawer styles, which is why it launches the activities. Your app likely has a different purpose. |
So , I should use fragment or use intent.putExtra. I have 2 options ? |
@trinhvanminh2009 I suggest you look into fragments. That way you only have one drawer and you don't have to worry about the selection. Have a look at how to switch fragments, which you will do so when you receive a drawer click |
Yeah . I used fragment for google maps and dialog fragment. But this way I never try before. Thank you so much . I'll try that right now . |
@AllanWang thanks for answering :) |
@trinhvanminh2009 many people have already achieved it by using activities. It's simply more complicated as the Most people who did this created a Also remember that you can And you can always handle more complex tasks by handling some things with the listener. |
@mikepenz Thanks for support. I'm using the Drawer in BaseActivity. But it's not working perfect like me think. Maybe my code have some problem. I think using Fragment is better idea. Using BaseActivity also good , but how to change activity not using intent or how to set Selection in onDrawerItemClickListener ? |
I just open activity but not click into any items. But function withOnDrawerItemClickListener run fist time ?
The text was updated successfully, but these errors were encountered: