list - Android spinner gets values from file -
i have problem android spinner. i'm trying spinner drop downwards values list reads values file.. have 2 spinners. when first spinner value selected sec spinner displays corresponding values. @ moment read spinner values list made, want read them text file.
public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { string foodcategory = string.valueof(spfoodcategory.getselecteditem()); if(foodcategory.contentequals("milk products")) { list<string> list = new arraylist<string>(); list.add("joghurt r2.2% 100g - 76 kcal"); list.add("cheese r24% - 332 kcal"); list.add("milk 100ml - 56 kcal"); arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, list); dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter.notifydatasetchanged(); spfoodproduct.setadapter(dataadapter); } if(foodcategory.contentequals("meat , fish products")) { list<string> list = new arraylist<string>(); list.add("chicken 100g - 142 kcal"); list.add("minced meat r20% 100g - 246 kcal"); list.add("herring 100g - 235 kcal"); list.add("ham 100g - 130kcal"); list.add("egg 100g - 135 kcal"); list.add("bacon 100g - 301 kcal"); arrayadapter<string> dataadapter2 = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, list); dataadapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter2.notifydatasetchanged(); spfoodproduct.setadapter(dataadapter2); } }
you can set files want in assets
folder read them line line , add together lists.
here's how read assets
list<string> list = new arraylist<string>(); inputstream txt = getassets().open("file.txt"); bufferedreader in = new bufferedreader(new inputstreamreader(txt, "utf-8")); string str; while ((str=in.readline()) != null) { list.add(str); } in.close();
android list arraylist spinner text-files
No comments:
Post a Comment