how "max" attribute during oncreateview()? if can attrs.getattributecount() work solve problem.
<?xml version="1.0" encoding="utf-8"?> <preferencescreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/livewallpaper_settings" android:key="livewallpaper_settings" > <com.example.myapp.seekbarpreference1 android:persistent="true" android:key="keyitems" android:title="items" android:defaultvalue="50" android:max="200" /> <com.example.myapp.seekbarpreference1 android:persistent="true" android:key="keyitemstwo" android:title="items two" android:defaultvalue="5" android:max="10" /> </preferencescreen>
here simplified class. xmlpullparser not return parse.
public final class seekbarpreference1 extends preference implements onseekbarchangelistener { private static int _maxvalue = 0; private int _currentvalue = 0; private textview _value; private sharedpreferences _preferences; public seekbarpreference1(context context, attributeset attrs) { super(context, attrs); _preferences = preferencemanager.getdefaultsharedpreferences(context); // // these values correct // log.d("prefs", " "); log.d("prefs", "seekbarpreference1"); log.d("prefs", "key: " + getkey()); log.d("prefs", "attrcount: " + attrs.getattributecount()); log.d("prefs", "####"); } @override protected view oncreateview(viewgroup parent) { xmlpullparser attrs = parent.getresources().getxml(r.xml.livewallpaper_settings); log.d("prefs", " "); log.d("prefs", "oncreateview"); log.d("prefs", "key: " + getkey()); // correct key output log.d("prefs", "attrcount: " + attrs.getattributecount()); // -1 log.d("prefs", "####"); } }
log output
seekbarpreference1 key: keyitems attrcount: 7 #### seekbarpreference1 key: keyitemstwo attrcount: 7 #### oncreateview key: keyitems attrcount: -1 #### oncreateview key: keyitemstwo attrcount: -1 ####
it seems me if can correct key, title, summery, etc. (from oncreateview) there should simple way other attributes.?
if try , store attributes seekbarpreference1(), lost oncreateview() called.
summery: attributes current "this" oncreateview();
i got figured out.
public seekbarpreference1(context context, attributeset attrs) { super(context, attrs); _preferences = preferencemanager.getdefaultsharedpreferences(context); // save shared prefs here // saved seekbar max && current value // below (int = 0; < attrs.getattributecount(); i++) { if (attrs.getattributename(i).equals("max")) _preferences.edit().putstring(getkey() +"max", ""+ attrs.getattributevalue(i)).commit(); } }
then retrieve data oncreateview()
protected view oncreateview(viewgroup parent) { // retrieve data // have correct data _maxvalue = integer.parseint(_preferences.getstring(getkey() +"max", "")); }
now can use same class multiple times, finally...
Comments
Post a Comment