android - Know which tab is selected -



android - Know which tab is selected -

i have actionbar implemented 4 tabs. each tab loads fragment. in each fragment, have imageview bluetooth logo, when bluetooth beingness conected, logo should blink. have method implemented on fragments way:

public void makebluetoothblink() { bticon.setimageresource(r.drawable.bluetooth_blink); animationdrawable frameanimation = (animationdrawable) bticon.getdrawable(); frameanimation.start(); }

now, in activity, have listener bluetooth state, boy when connecting, should observe fragment visible. other posibility observe tab selected. booth options should work.

my approach has been define tag each fragment , check 1 visible , phone call method there create bluetooth logo blink. doesn't recognize method fragment. that's why thought detecting tab selected may easier, i'm not sure it, , don't know how it.

public void onconnecting() { //call fragment blink method fragment current_fragment = getsupportfragmentmanager().findfragmentbytag(tab1); if (current_fragment.isvisible()) { current_fragment.makebluetoothblink(); } }

from android development docs

public abstract actionbar.tab getselectedtab () added in api level 11 returns selected tab if in tabbed navigation mode , there @ to the lowest degree 1 tab present. returns selected tab or null

android android-fragments tabs

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -