我尝试使用Parse.com框架刷新当前登录的用户,并在每次打开导航抽屉菜单时更新标签。不幸的是,我无法确定每次打开时都会调用哪种方法。我已尝试在NavigationDrawerAdapter中执行此操作:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (listofItems.get(position) instanceof NavigationDrawerListItem) {
convertView = mInflater.inflate(
R.layout.navigation_drawer_list_item, null);
return convertView;
} else if (listofItems.get(position) instanceof NavigationDrawerUserInformation) {
convertView = mInflater.inflate(
R.layout.navigation_drawer_list_object, null);
final TextView userName = (TextView) convertView
.findViewById(R.id.txtvDrawerFirstItemText1);
ParseUser.getCurrentUser().fetchInBackground(
new GetCallback<ParseUser>() {
@Override
public void done(ParseUser user, ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
if (ParseAnonymousUtils.isLinked(user)) {
userName.setText("Welcome Guest");
} else {
userName.setText("Welcome, "
+ user.getUsername() + "!");
}
}
}
});
return convertView;
}
return null;
}
但标签永远不会更新新信息,除非我通过单击菜单中的另一个并再次打开菜单导航离开当前片段。列表中的每个项目只是一个新片段,所有片段都在同一个Activity中打开。
答案 0 :(得分:0)
当您打开抽屉时,会调用以下方法:
public void onDrawerOpened(View drawerView)
当您关闭抽屉时,会调用以下方法:
public void onDrawerClosed (View drawerView)