Android 知道选择了哪个选项卡

Android 知道选择了哪个选项卡,android,android-fragments,tabs,Android,Android Fragments,Tabs,我用4个选项卡实现了ActionBar。每个选项卡加载一个片段。在每个片段中,我都有一个带有蓝牙标志的图像视图,当连接蓝牙时,这个标志应该闪烁。我以这种方式在所有片段上实现了此方法: public void makeBluetoothBlink() { btIcon.setImageResource(R.drawable.bluetooth_blink); AnimationDrawable frameAnimation = (AnimationDrawable) btIcon.

我用4个选项卡实现了ActionBar。每个选项卡加载一个片段。在每个片段中,我都有一个带有蓝牙标志的图像视图,当连接蓝牙时,这个标志应该闪烁。我以这种方式在所有片段上实现了此方法:

public void makeBluetoothBlink() {
    btIcon.setImageResource(R.drawable.bluetooth_blink);
    AnimationDrawable frameAnimation = (AnimationDrawable) btIcon.getDrawable();
    frameAnimation.start();
}
现在,在活动中,我有一个蓝牙状态的侦听器,当它连接时,它应该检测哪个片段是可见的。另一个可能性是检测选择了哪个选项卡。摊位选项应该可以完成这项工作

我的方法是为每个片段定义一个标记,然后检查哪个片段是可见的,并调用该方法使蓝牙徽标闪烁。但它无法从片段中识别方法。所以,这就是为什么我认为检测哪个标签被选中可能更容易,但我不确定,我不知道怎么做

public void onConnecting() {
    //Call fragment blink method
    Fragment current_fragment = getSupportFragmentManager().findFragmentByTag(tab1);
    if (current_fragment.isVisible()) {
        current_fragment.makeBluetoothBlink();
    }
}

public abstract ActionBar.Tab getSelectedTab ()

Added in API level 11
Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

Returns
The currently selected tab or null