我在我的主要活动中使用BottomBar并且我正在关注来自 github 的示例代码,他在其中将侦听器添加到选项卡:
this.bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
switch (tabId) {
case R.id.tab_evaluate :
Toast.makeText(getApplicationContext(),"Evaluate",Toast.LENGTH_SHORT).show();
break;
case R.id.tab_info:
Toast.makeText(getApplicationContext(),"INfo",Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getApplicationContext(),"Other",Toast.LENGTH_SHORT).show();
break;
}
}
});
它工作得很好,我看到了所有的祝酒词。
我的问题:在我的主要活动中,我有两种方法,我想根据选定的选项卡调用它们:
private void showQrCodeView(){
this.contentFrame.setVisibility(View.GONE);
this.qrCodeReaderView.setVisibility(View.VISIBLE);
}
private void hideQrCodeView(){
this.contentFrame.setVisibility(View.VISIBLE);
this.qrCodeReaderView.setVisibility(View.GONE);
}
为此,我尝试了这个,它不会引发任何错误,但也不起作用。
case R.id.tab_evaluate :
Toast.makeText(getApplicationContext(),"Evaluate",Toast.LENGTH_SHORT).show();
MainActivity.this.showQrCodeView();
break;
我的问题是如何调用 MainActivity 中的方法OnTabSelectListener
?