I'm finding myself rewriting the same code for my actionBar (actionBarSherlock) list in 3 separate activities. All 3 are using the same actionBar, which has 3 items which launch Activities #1, #2, #3.
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<CharSequence> list = ArrayAdapter
.createFromResource(this, R.array.action_list, android.R.layout.simple_dropdown_item_1line);
list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(list, this);
getSupportActionBar().setListNavigationCallbacks(adapter, this);
getSupportActionBar().setSelectedNavigationItem(position);
I have 2 Questions:
Should I be using 1 activity with 3 fragments in this case? My activities are a listview, a mapview, and a form view. I'm unsure of whether this is the right case to use Fragments, as each of those views uses the whole screen in my case.
Using 3 different activities, can I create a new class whose sole purpose is to configure my ActionBar for me using the code above so the initialization code is only in 1 place?
Something like:
public class setupActionBar {
private ActionBar myBar;
public setupActionBar(ActionBar myBar){
this.myBar = myBar;
//Do Initialization on myBar;
}
public ActionBar getMyBar(){
return myBar;
}
}
Watch this video. He creates a BaseActivity
that subclasses all of the Activities used in the program.
Neat little trick ;)
You can thank me later :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With