mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

I can't select Secondary Drawer Item. What can be the problem? #1010

Closed ghost closed 8 years ago

ghost commented 8 years ago
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.entypo_typeface_library.Entypo;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic;
import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.holder.BadgeStyle;
import com.mikepenz.materialdrawer.holder.StringHolder;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
import com.smk.adapter.CitySpinnerAdapter;
import com.smk.adapter.TownshipSpinnerAdapter;
import com.smk.clients.NetworkEngine;
import com.smk.model.City;
import com.smk.model.MyOrderList;
import com.smk.model.Township;
import com.smk.model.User;
import com.smk.skalertmessage.SKToastMessage;
import com.smk.util.StoreUtil;
import com.thuongnh.zprogresshud.ZProgressHUD;
import java.util.List;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class CargoPlaceActivity extends BaseAppCompatActivity {

    private Drawer result;
    PrimaryDrawerItem cargoPlace, drawerPending, drawerProgressing, drawerDelivered;
    SecondaryDrawerItem settingUpdateProfile, setting, logout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cargo_place);

        toolbar = (Toolbar) findViewById(R.id.toolbar_title);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        AccountHeader headerResult = new AccountHeaderBuilder()
                .withActivity(this)
                .withHeaderBackground(new ColorDrawable(getResources().getColor(R.color.colorPrimary)))
                .addProfiles(
                        new ProfileDrawerItem().withName(user.getName()).withEmail(user.getEmail()).withIcon(getIconicDrawable(GoogleMaterial.Icon.gmd_account_circle.toString(), R.color.colorWhite, 48))
                )
                .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                    @Override
                    public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
                        return false;
                    }
                })
                .build();

        result = new DrawerBuilder()
                .withActivity(this)
                .withToolbar(toolbar)
                .withAccountHeader(headerResult)
                .addDrawerItems(
                        cargoPlace = new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(Entypo.Icon.ent_shopping_bag).withIdentifier(1),
                        drawerPending = new PrimaryDrawerItem().withName(R.string.drawer_item_pending).withIcon(MaterialDesignIconic.Icon.gmi_truck).withBadge("0").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withIdentifier(2),
                        drawerProgressing = new PrimaryDrawerItem().withName(R.string.drawer_item_progressing).withIcon(MaterialDesignIconic.Icon.gmi_truck).withBadge("0").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withIdentifier(3),
                        drawerDelivered = new PrimaryDrawerItem().withName(R.string.drawer_item_delivered).withIcon(MaterialDesignIconic.Icon.gmi_truck).withBadge("0").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withIdentifier(4),
                        settingUpdateProfile = new SecondaryDrawerItem().withName(R.string.drawer_item_settings_my_profile).withIcon(GoogleMaterial.Icon.gmd_account_box).withIdentifier(5),
                        setting = new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(6).withSelectable(false),
                        logout = new SecondaryDrawerItem().withName(R.string.drawer_item_logout).withIcon(CommunityMaterial.Icon.cmd_logout).withIdentifier(7).withSelectable(false)

                )
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            Intent intent = null;
                            if (drawerItem.getIdentifier() == 1) {
                                intent = new Intent(CargoPlaceActivity.this, CargoPlaceActivity.class);
                            } else if (drawerItem.getIdentifier() == 2) {
                                intent = new Intent(CargoPlaceActivity.this, MyPendingCargoActivity.class);
                            } else if (drawerItem.getIdentifier() == 3) {
                                intent = new Intent(CargoPlaceActivity.this, MyProgressingCargoActivity.class);
                            } else if (drawerItem.getIdentifier() == 4) {
                                intent = new Intent(CargoPlaceActivity.this, MyDeliveredCargoActivity.class);
                            } else if (drawerItem.getIdentifier() == 5) {
                                intent = new Intent(CargoPlaceActivity.this, UpdateProfileActivity.class);
                            }
                            if (intent != null) {
                                CargoPlaceActivity.this.startActivity(intent);
                            }
                        }
                        return false;
                    }
                })
                .withSavedInstance(savedInstanceState)
                .withShowDrawerOnFirstLaunch(true)
                .build();

        result.openDrawer();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState = result.saveInstanceState(outState);
        super.onSaveInstanceState(outState);
    }
}
mikepenz commented 8 years ago

@PeterPhyo the fact that you defined it to be non selectable

remove

.withSelectable(false)
ghost commented 8 years ago

I have been already removed. .withSelectable(false) But I can't select Secondary Item.

settingUpdateProfile = new SecondaryDrawerItem().withName(R.string.drawer_item_settings_my_profile).withIcon(GoogleMaterial.Icon.gmd_account_box).withIdentifier(5),

mikepenz commented 8 years ago

@PeterPhyo won't it trigger the onItemClick listener or do you mean something else?

ghost commented 8 years ago

Thank You, No No, I have a problem in UpdateProfileActivity.java :D