My activity
class is like following:
/*ToolBar SetUp*/
app_toolBar = (Toolbar) findViewById(R.id.toolbar_header);
setSupportActionBar(app_toolBar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
String TITLES[] = {"Home", "Search", "HalalRewards", "Contact Us", "User Guide", "F.A.Q", "Settings", "Share"};
int ICONS[] = {R.drawable.ic_action_home, R.drawable.ic_search, R.drawable.ic_rewardsss, R.drawable.ic_contact, R.drawable.ic_uguide, R.drawable.ic_faq, R.drawable.ic_settings, R.drawable.ic_shareee};
String NAME = "ESignature IT Solution";
String EMAIL = "info@esignature.com.np";
int PROFILE = R.drawable.intologo;
/*Drawer SetUp*/
mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View
mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size
mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE);
// Creating the Adapter of MyAdapter class(which we are going to see in a bit)
// And passing the titles,icons,header view name, header view email,
// and header view profile picture
mRecyclerView.setAdapter(mAdapter); // Setting the adapter to RecyclerView
mRecyclerView.setOnClickListener(new DrawerItemClickListener());
mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager
mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view
mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, app_toolBar, R.string.openDrawer, R.string.closeDrawer) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
// TO DO Execute code when Drawer view open
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
// TO DO Execute code when once Drawer is close
}
};
Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
return true;
}
return super.onOptionsItemSelected(item);
}
// create fragmrnt loader funtion
// id get from adapter ....
/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements AdapterView.OnItemClickListener, View.OnClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*selectItem(position);*/ ///////////
// display view for selected nav drawer item
displayView(position);
}
@Override
public void onClick(View v) {
}
}
// Diplaying fragment view for selected nav drawer list item
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
/*case 0:
fragment = new Fragment();
break;*/
case 1:
fragment = new SearchActivity();
break;
case 2:
fragment = new HalalRewardsActivity();
break;
case 3:
fragment = new ContactUsFragment();
break;
case 4:
fragment = new GuideFragment();
break;
case 5:
fragment = new FaqFragment();
break;
case 6:
fragment = new SettingsFragment();
break;
case 7:
fragment = new ShareFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
Drawer.closeDrawer(mRecyclerView);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
}
I am a new programmer. So proper help would be praiseworthy. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire