动作条导航列表 - 使用相同的动作条在多个活动;初始化在一个地方 [英] ActionBar Navigation List - Use same ActionBar in multiple activities; Initialize in one place
问题描述
我发现自己重写相同的code为3个独立的活动,我的动作条(actionBarSherlock)名单。所有3都使用相同的动作条,其中有3个项目其中发射活动#1,#2,#3。
getSupportActionBar()setNavigationMode(ActionBar.NAVIGATION_MODE_LIST)。
ArrayAdapter< CharSequence的>名单= ArrayAdapter
.createFromResource(这一点,R.array.action_list,android.R.layout.simple_dropdown_item_1line);
list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
getSupportActionBar()setListNavigationCallbacks(列表中,这一点)。
getSupportActionBar()setListNavigationCallbacks(适配器,这一点)。
getSupportActionBar()setSelectedNavigationItem(位置)。
我有2个问题:
-
我应该使用1活性与3个片段在这种情况下?我的活动是一个列表视图,一个图形页面,和表单视图。我不能确定这是否是正确的情况下使用的片段,每个这样的看法使用整个屏幕在我的情况。
-
使用3种不同的活动,我可以创造的唯一目的就是使用code以上这样的初始化code仅在1处配置我的动作条对我来说是新的类?
是这样的:
公共类setupActionBar {
民营动作条myBar;
公共setupActionBar(动作条myBar){
this.myBar = myBar;
//完成初始化上myBar;
}
公共动作条getMyBar(){
返回myBar;
}
}
表<一个href="http://www.youtube.com/watch?v=C8QIubc_9CY&feature=context-shows&list=SL&safety_mode=true&persist_safety_mode=1&safe=active">this影片。他创建了一个 BaseActivity
子类的所有的程序中使用的活动。
整洁的小伎俩;)
您可以稍后感谢我:D
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
这篇关于动作条导航列表 - 使用相同的动作条在多个活动;初始化在一个地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!