我已经成功地显示了多个帐户,名称和电子邮件。但我也希望能够在传递名称和电子邮件时传递一个唯一的数字,这样当我单击帐户时,我可以为电子邮件、名称和唯一数字干杯。目前,我只能敬酒的名称和电子邮件的当前配置文件时,点击。
这是我的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的数组中的关键字存储,那么在我实现toast电子邮件时,它会将该电子邮件作为参数传递给电子邮件所在的数组搜索,并返回corpare_no。
发布于 2017-03-03 15:37:18
我想您已经在gradle中包含了MaterialDrawer,使用material抽屉库作为.Update模块,这个特定的布局文件显示了姓名、电子邮件和个人资料图片的数据。
填写公司编号在name参数下面添加标签,并再次构建和重新加载您应用程序,.You可以使用您提供的id访问该标签。
布局XML文件链接
[https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/res/layout/material_drawer_compact_persistent_header.xml][1]https://stackoverflow.com/questions/42572973
复制相似问题