简体   繁体   中英

How to add param on MaterialDrawer

I have managed to display multiple accounts , the name and the email. But I also wanted to be able to pass a unique number as I was passing the name and the email so that when I click the account I can toast the email , name , and the unique number. Currently am only able to toast the Name and the email of the current profile when clicked.

This is my Json

 "sacco_info": [
{
  "name": "Alex Wanjala",
  "email": "wanjala@gmail.com"
  "corporate_no": "169500"
}
 ]

This is my code

   Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

    // Create the AccountHeader
    Api.getVolley(this, Api.GetCorporateNumber,"{\n" +
            "  \"authorization_credentials\": {\n" +
            "    \"api_key\": \""+Const.getInstance().getAuthorizationcredentials().getApi_key()+"\",\n" +
            "    \"token\": \""+Const.getInstance().getAuthorizationcredentials().getToken()+"\"\n" +
            "  },\n" +
            "  \"msisdn\": \""+Const.getInstance().getMember().getMSDN()+"\"\n" +
            "}",new Api.VolleyCallback() {

        @Override
        public void onSuccess(String response) {
            try {
                JSONObject jsonObj = new JSONObject(response);
                JSONArray jsonArray= jsonObj.getJSONArray("sacco_info");

                for(int i=0;i<jsonArray.length();i++){

                    JSONObject jsonObject = jsonArray.getJSONObject(i);

                    profile =  new ProfileDrawerItem().withName(jsonObject.getString("name"))
                            .withEmail(jsonObject.getString("email")).withIcon(getResources().getDrawable(R.drawable.profilepic));
                    headerResult.addProfiles(profile);

                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    });


    headerResult = new AccountHeaderBuilder()
            .withActivity(DashboardMain.this)
            .withHeaderBackground(R.drawable.materiale)
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
                    Toast.makeText(getApplicationContext(), profile.getEmail().toString(),Toast.LENGTH_LONG).show();
                    Toast.makeText(getApplicationContext(), profile.getName().toString(),Toast.LENGTH_LONG).show();
                   //Toast the corporate_no here
                    return false;
                }
            })
            .build();


    result = new DrawerBuilder()
            .withActivity(DashboardMain.this)
            .withToolbar(toolbar)
            .withAccountHeader(headerResult)
            .addDrawerItems(
                    item1, item2,item3, item4, item5, item6,
                    new DividerDrawerItem(),
                    item7, item8,item9,item10,item11
            )
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    // do something with the clicked item :D
                    onNavigationItemSelected(position);
                    return false;
                }
            })
            .build();

Or if there is a way I can store key value pairs email as a key in an array holding the email and the corparate_no , then at the time where I have implemented toast the email, it passes that email as parameter to the array search where the email exist and returns the corpare_no .

I think your have included MaterialDrawer in gradle use the material drawer library as module .Update this specific file of layout thats showing this data of name email and profile pic .

Put corporate No. label just below name parameter and build and reload your app again .You can access that label using its id you have provided .

Layout XML File link

[https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/res/layout/material_drawer_compact_persistent_header.xml][1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM