1
雖然我一直在四處尋找,但找不到正確的答案。 在我的導航抽屜標題中,我向用戶提供了他的圖像和名稱,但是我也允許用戶從應用程序更改他/她的名字和圖像。 這些更改存儲在會話管理器中。 現在我想在我的導航抽屜標題中反映這些更改。 一切工作正常,因爲當我關閉應用程序並再次運行它顯示更改。 因此,現在我需要的是一種刷新導航抽屜標題的方法。導航抽屜中的刷新標題
從配置文件片段中的庫中選擇圖像。
private void onSelectFromGalleryResult(Intent data) {
String selectedImagePath = getPathFromCameraData(data, getActivity());
Bitmap bm;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
final int REQUIRED_SIZE = 200;
int scale = 1;
while (options.outWidth/scale/2 >= REQUIRED_SIZE
&& options.outHeight/scale/2 >= REQUIRED_SIZE)
scale *= 2;
options.inSampleSize = scale;
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(selectedImagePath, options);
bitmap = bm;
profilephoto = BitMapToString(bm);
session.setprofilepic(profilephoto);// make changes in session.
profilepic.setImageBitmap(bm);
}
首頁活動
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepageactivity);
session = new SessionManager(getApplicationContext());
mTitle = mDrawerTitle = getTitle();
topToolBar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(topToolBar);
//topToolBar.setLogo(R.drawable.logo);
topToolBar.setLogoDescription(getResources().getString(R.string.logo_desc));
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
LayoutInflater inflater = getLayoutInflater();
listHeaderView = inflater.inflate(R.layout.header_list, null, false);
//ImageView profile = (ImageView)listHeaderView.findViewById(R.id.profile_picture);
TextView name = (TextView)listHeaderView.findViewById(R.id.headername);
profilepic = (ImageView)listHeaderView.findViewById(R.id.profile);
user = session.getUserDetails();
profilepic.setImageBitmap(StringToBitMap(user.get(SessionManager.KEY_PROFILEPIC)));
name.setText(user.get(SessionManager.KEY_NAME));
mDrawerList.addHeaderView(listHeaderView); ////// HEADER ADDED
List<ItemObject> listViewItems = new ArrayList<ItemObject>();
listViewItems.add(new ItemObject("Attendance", R.drawable.attendance));
// listViewItems.add(new ItemObject("Time table", R.drawable.timetable));
// listViewItems.add(new ItemObject("Class 1", R.drawable.classicon));
adapter = new CustomAdapter(this, listViewItems);
mDrawerList.setAdapter(new CustomAdapter(this, listViewItems));
mDrawerToggle = new ActionBarDrawerToggle(Homepageactivity.this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(mDrawerTitle);
profilepic.setImageBitmap(StringToBitMap(user.get(SessionManager.KEY_PROFILEPIC)));
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.setDrawerIndicatorEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// make Toast when click
Toast.makeText(getApplicationContext(), "Position " + position, Toast.LENGTH_LONG).show();
selectItemFragment(position);
}
});
}
Rishabh,你解決了你的問題嗎?如果是,那麼請發佈您的解決方案(代碼行) –