我的应用在activity_main.xml中包含bottomNavigationView和TabLayout。使用switch-case选择所选的Navigation Fragment,并以编程方式命名选项卡:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText("A"));
tabLayout.addTab(tabLayout.newTab().setText("B"));
tabLayout.addTab(tabLayout.newTab().setText("C"));
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.navigation);
bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.navigation_national:
selectedFragment = ItemOneFragment.newInstance();
break;
case R.id.navigation_international:
selectedFragment = ItemTwoFragment.newInstance();
break;
case R.id.navigation_blackboard:
selectedFragment = ItemThreeFragment.newInstance();
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;
}
});
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, ItemOneFragment.newInstance());
transaction.commit();
}
}
现在我想根据所选的bottomNavigation选项更改选项卡名称。为什么我不能只添加addText("");对不同案件的陈述?
答案 0 :(得分:0)
var signal_handler = create_signal_handler(item);
item.someValueChanged.connect(signal_handler);
...
function create_signal_handler(item)
{
return function() { return handler(item); }
}