我有一个问题,在我的应用程序中实现导航。我想用Spinner
之类的菜单,在那里你可以选择你感兴趣的item
并获得对应的数据。然后这些数据将被设置为ActionBar选项卡。导航在应用程序:微调+ ActionBar标签
我实现了两个微调和标签,但有一个问题发生。 Android,不允许在OnItemSelectedListener
中使用可变变量,而我需要它。
final ActionBar.Tab tabToday= actionBar.newTab().setText("Today");
final ActionBar.Tab tabSoon = actionBar.newTab().setText("Soon");
..............................
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
switch(arg2){
case 0:
tabToday.setTabListener(new CustomTabListener(MainActivity.this,"item_1", "url"));
tabSoon.setTabListener(new CustomTabListener(MainActivity.this,"item_1", "url_2"));
actionBar.addTab(tabToday);
actionBar.addTab(tabSoon);
break;
case 1:
tabToday.setTabListener(new CustomTabListener(MainActivity.this,"item_2", "url_3"));
tabSoon.setTabListener(new CustomTabListener(MainActivity.this,"item_2", "url_4"));
break;
case 2:
tabToday.setTabListener(new CustomTabListener(MainActivity.this,"item_3", "url_5"));
tabSoon.setTabListener(new CustomTabListener(MainActivity.this,"item_3", "url_6"));
break;
}
}
的问题是,我不能使用不final
变量,由于这种情况的发生:
有没有什么办法来解决这个问题,但仍然是相同的导航? 感谢您的阅读,任何帮助将不胜感激。 :)
编辑: 问题不是出在最后的变量,但问题依然存在:((
你不能让tabToday和tabSoon的最终副本,并使用监听器里的变量,像这样: 最终ActionBar.Tab tabTodayCopy = tabToday。那么今天就不必是最后的决赛了。 – 2013-03-21 18:42:00
tabToday不会是最终的,但这些最终副本将转到actionBar。最后一切都会是一样的:( – 2013-03-21 18:53:09
嘿,你能给一个提示你怎么能够添加标签和微调都到你的应用程序?我面临的问题 – Harshit 2014-02-05 07:17:58