I feel really dumb asking this but cant get it to work... I have a Navigation Drawer in my app and a second navigation drawer on the right side of my app i have gotten the icons and the names in it to be different than the first one... however the actions when they are clicked are the same ones that are in the left drawer... How to get it to work separately.
Here is my MainActivity where the actions for the first drawer are set.
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
String[] stringArray = getResources().getStringArray(R.array.section_titles);
if (number >= 1) {
mTitle = stringArray[number - 1];
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
if(data==null){
webView.loadUrl("file:///android_asset/index.html"); } else {
data = null;
}
break;
case 2:
mTitle = getString(R.string.title_section2);
if (webView.canGoBack())
webView.goBack();
break;
case 3:
mTitle = getString(R.string.title_section3);
if (webView.canGoForward())
webView.goForward();
break;
case 4:
mTitle = getString(R.string.title_section4);
webView.reload();
break;
case 5:
mTitle = getString(R.string.title_section5);
if(getActionBar().isShowing()){
getActionBar().hide();
}else{
getActionBar().show();}
break;
}
}
}
Here is the NavigationDrawerFragment for first drawer
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
final TypedArray typedArray = getResources().obtainTypedArray(R.array.sections_icons);
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
getResources().getStringArray(R.array.sections)
) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
int resourceId = typedArray.getResourceId(position, 0);
Drawable drawable = getResources().getDrawable(resourceId);
((TextView) v).setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
return v;
}
});
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
The strings.xml for both drawers
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
<string name="title_section1">Home</string>
<string name="title_section2">Back</string>
<string name="title_section3">Forward</string>
<string name="title_section4">Refresh</string>
<string name="title_section5">Fullscreen</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string-array name="sections">
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
</string-array>
<string-array name="section_titles">
<item>Section T1</item>
<item>Section T2</item>
<item>Section T3</item>
<item>Section T4</item>
<item>Section T5</item>
</string-array>
<string-array name="sections_icons">
<item>@drawable/ic_action_home</item>
<item>@drawable/ic_action_back</item>
<item>@drawable/ic_action_forward</item>
<item>@drawable/ic_action_refresh_enabled</item>
<item>@drawable/ic_action_full_screen1</item>
</string-array>
<string-array name="sections2">
<item>section ha</item>
<item></item>
<item></item>
<item></item>
</string-array>
<string-array name="section_titles2">
<item>Section T1</item>
<item>Section T2</item>
<item>Section T3</item>
<item>Section T4</item>
</string-array>
<string-array name="sections_icons2">
<item>@drawable/ic_launcher</item>
<item>@drawable/ic_launcher</item>
<item>@drawable/ic_launcher</item>
<item>@drawable/ic_launcher</item>
</string-array>
</resources>
And lastly the NavigationDrawerFragment2 for the right drawer that i need to change the actions
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer2, container, false);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
final TypedArray typedArray = getResources().obtainTypedArray(R.array.sections_icons2);
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
getResources().getStringArray(R.array.sections2)
) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
int resourceId = typedArray.getResourceId(position, 0);
Drawable drawable = getResources().getDrawable(resourceId);
((TextView) v).setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
return v;
}
});
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
Aucun commentaire:
Enregistrer un commentaire