android - How to get the current fragment in a Preference Activity? -
i've implemented nfc scanner , when tag scanned onnewintent
method gets called successfully, so:
@override protected void onnewintent(intent intent) { setintent(intent); resolveintent(intent); }
in resolveintent
want update ui based on scanned tag. problem can't figure out how reference fragment.
i thought use isvalidfragment
method hold of fragment, no luck far:
protected boolean isvalidfragment(string fragmentname) { if (fragmentname != null && !fragmentname.equals("")) { fragment f = getfragmentmanager().findfragmentbyid(r.id.myfragment); // null if (f != null && f instanceof myfragment) myfragment = (myfragment) f; } return preferencefragment.class.getname().equals(fragmentname) || generalpreferencefragment.class.getname().equals(fragmentname) || myfragment.class.getname().equals(fragmentname); }
so, thing need reference current fragment, need check if myfragment
, , call method updates ui.
i found few similar questions, still can't figure out. tried using interface , make callback, still don't know how reference fragment.
edit: pref_headers.xml
file:
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"> <header android:fragment=".settingsactivity$generalpreferencefragment" android:title="@string/pref_header_general" /> <header android:fragment=".settingsactivity$myfragment" android:id="@+id/myfragment" android:title="test" /> </preference-headers>
header class not extending fragment. why null object. trying cast object 1 cannot polymorph or trying find view way of fragment.
open ddms , try dump view hiearchy understand how preferenceactivity works. looks parses given xml , inflates view components build ui.
maybe can give try findviewbyid or load different preference xml files change ui.
Comments
Post a Comment