Android : Split Action Bar items show up on some pages but not others

on Friday, December 5, 2014


So I've made a split action bar with entries for navigation. I set the menu items to show always and added the meta-data tags to each activity and the app regarding showing the split action bar. The split action bar shows up on all pages. My navigation buttons show up on all the pages but one (where they go into the context menu, rather than displaying). The page its not working on contains tabs and an imageview on the top action bar, however I tried removing the tabs and changing the imageview being loaded at the top to an edittext being used on a different page and it still did not work.


AndroidManifest.xml (The non-working activity is StopPage):



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.example.whatever"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:uiOptions="splitActionBarWhenNarrow">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchByName"
android:label="@string/title_activity_searchable" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".StopPage"
android:label="@string/title_activity_stop_page" >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
<activity
android:name=".SearchByRoute"
android:label="@string/title_activity_search_by_route" >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
</application>

</manifest>


split_action_bar.xml:



<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_stops"
android:title="Stops"
yourapp:showAsAction="always"/>
<item android:id="@+id/action_routes"
android:title="Routes"
yourapp:showAsAction="always" />
<item android:id="@+id/action_faves"
android:title="Favourites"
yourapp:showAsAction="always" />
</menu>


Code being used to inflate (working in all other activities):



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.split_action_bar, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Action bar item click handling
int id = item.getItemId();
if (id == R.id.action_stops) {
Intent intent = new Intent(this, SearchByName.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
return true;
}
else if(id == R.id.action_routes) {
Intent intent = new Intent(this, SearchByRoute.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
return true;
}
else if(id == R.id.action_stops) {
Intent intent = new Intent(this, SearchByName.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}


Code related to filling the top action bar (in the non-working activity's onCreate):



ActionBar actionBar = getActionBar();
actionBar.setNavigationMode( ActionBar.NAVIGATION_MODE_TABS );

actionBar.setCustomView(R.xml.result_list_bar);

favouritesButton = (ImageView) actionBar.getCustomView().findViewById(R.id.result_page_favourites);

favouritesButton.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (isInFavourites()){
Toast.makeText(getBaseContext(), "Stop removed from favourites!", Toast.LENGTH_SHORT).show();
removeStopFromFavourites();
}
else{
Toast.makeText(getBaseContext(), "Stop added to favourites!", Toast.LENGTH_SHORT).show();
addStopToFavourites();
}
}

});
actionBar.addTab(
actionBar.newTab().setText(R.string.tab1)
.setTabListener(new ActionBar.TabListener(){

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
currentView = "tracked";

setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);

lv.setVisibility(ListView.INVISIBLE);
dayOption.setVisibility(Spinner.INVISIBLE);
routeOption.setVisibility(Spinner.INVISIBLE);

tripHeadsign = null;
//tempRoute.setVisible(false);
String url = "http://nextride.brampton.ca/mob/home.aspx?stop=" + stopNumber;
TrackedTimesForStopHandler download = new TrackedTimesForStopHandler();
download.execute(url);
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

}) );

actionBar.addTab(
actionBar.newTab().setText(R.string.tab2)
.setTabListener(new ActionBar.TabListener(){

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
currentView = "scheduled";

setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);

lv.setVisibility(ListView.INVISIBLE);

ScheduledTimesForStopHandler download = new ScheduledTimesForStopHandler();
download.execute(stopNumber);

}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

}) );

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);


Anyone have any ideas what's going wrong?


0 comments:

Post a Comment