我设法显示了多个帐户,名称和电子邮件。但是,我也希望在传递名称和电子邮件时传递唯一号码,以便当我单击帐户时,我可以敬酒电子邮件,名称和唯一号码。当前只能在单击当前个人资料的名称和电子邮件。
时。这是我的JSON
"sacco_info": [
{
"name": "Alex Wanjala",
"email": "wanjala@gmail.com"
"corporate_no": "169500"
}
]
这是我的代码
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();
或者如果有一种方法,我可以将密钥价值对作为持有电子邮件和corparate_no的数组中的密钥来存储,然后在我实施敬酒的时候,它将电子邮件作为参数传递给数组搜索电子邮件存在的位置并返回coldare_no。
我认为您在gradle中包含了Materialldrawer,将材料抽屉库用作模块。对此特定的布局文件进行了说明,显示了此名称电子邮件和配置文件的数据。
。将Corporate编号放在名称参数下方,然后再次构建和重新加载您的应用程序。您可以使用已提供的ID访问该标签。
布局XML文件链接
[https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/res/layout/material_drawer_compact_persistent_header.xml][1]