java - Scrollbar disappears when using SectionIndexer at specific sections on HoneyComb -
i'm using adapter listview
implements sectionindexer
. listview
has fastscrollenabled
set true in xml file. works great on android 2.2 , 2.3, when test application on tablet android 3.0, @ sections scrollbar disappears. example when scroll down list, @ elements beginning letters a-b scrollbar visible, letters c-h it's not, , after h again visible.
this adapter made sorting content alphabetically in listview fastscroll can used.
application designed api level 8, couldn't use fastscrollalwaysvisible.
here code of adapter:
public class alphabetsimpleadapter extends simpleadapter implements sectionindexer { private hashmap<string, integer> charlist; private string[] alphabet; public typeface tfsansmedium; public context mcontext; public int mresource; public int[] mto; public list<? extends map<string, ?>> mdata; public string mtitlekey; public alphabetsimpleadapter(context context, list<? extends map<string, ?>> data, int resource, string[] from, int[] to, string titlekey /* key sent in hashmap */) { super(context, data, resource, from, to); mdata = data; mtitlekey = titlekey; mcontext = context; mresource = resource; mto = new int[to.length]; ( int = 0; < to.length; ++) { mto[i] = to[i]; } charlist = new hashmap<string, integer>(); int size = data.size(); tfsansmedium = typeface.createfromasset(context.getassets(), "fonts/vitessesans-medium.otf"); for(int = 0; < size; i++) { // parsing first letter of hashmap element string ch = data.get(i).get(titlekey).tostring().substring(0, 1); ch = ch.touppercase(); if(!charlist.containskey(ch)) { charlist.put(ch, i); // using hashmap avoid duplicates } } set<string> sectionletters = charlist.keyset(); // set of first letters arraylist<string> sectionlist = new arraylist<string>(sectionletters); // creating arraylist able sort elements collections.sort(sectionlist, collator.getinstance(new locale("pl", "pl"))); // sorting elements alphabet = new string[sectionlist.size()]; sectionlist.toarray(alphabet); } // methods required sectionindexer @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater li = (layoutinflater)mcontext.getsystemservice(context.layout_inflater_service); v = li.inflate(mresource, null); } (int = 0; < mto.length; ++) { textview tv = (textview)v.findviewbyid(mto[i]); if (tv != null) tv.settypeface(tfsansmedium); } return super.getview(position, v, parent); } @override public int getpositionforsection(int section) { if(!(section > alphabet.length-1)) { return charlist.get(alphabet[section]); } else { return charlist.get(alphabet[alphabet.length-1]); } } @override public int getsectionforposition(int position) { return charlist.get(mdata.get(position).get(mtitlekey).tostring().substring(0, 1)); } @override public object[] getsections() { return alphabet; } }
charlist
hashmap store letters last appearing index when have 6 elements starting letter "a", value key "a" 5 , on.
alphabet
string array existing first letters.
i facing same problem. gave minimum sdk version 8 , traget 16 , wrote code below. , worked fine.
int currentapiversion = android.os.build.version.sdk_int; if (currentapiversion <= android.os.build.version_codes.froyo){ // froyo , above versions fblist.setfastscrollenabled(true); } else if(currentapiversion > android.os.build.version_codes.honeycomb){ // phones running sdk before froyo fblist.setfastscrollenabled(true); fblist.setfastscrollalwaysvisible(true); }
Comments
Post a Comment