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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -