android populate spinner from html form values (select tag) -


hi i'm looking @ best/simplest way populate spinner values select section of html page. spinner values must same ones present in html select section. i'm looking in simplest way possible. thought of following ideas:

  • read values html page (for example using lxml)
  • add values spinner (directly or if not possible after saving values in database)

does know simplest way (for both read part , population part)? there android object/class allowing directly link values html page spinner?

many in help! ben

i used jsoup in asynctask value , text of options , put them in text/value treemap (sorted hashmap) so:

class theatergetter extends asynctask<context, void, document> {         private context context;     @override     protected document doinbackground(context... contexts) {         context = contexts[0];         document doc = null;         try {             doc = jsoup.connect("http://landmarkcinemas.com").timeout(10000).get();         } catch (ioexception e) {             log.e("website connection error", e.getmessage());         }         return doc;     }      protected void onpostexecute(document doc) {         element alloptions = doc.select("select[id=campaign").first();         elements options = alloptions.getelementsbytag("option");         options.remove(0);         treemap<string, string> theaters = new treemap<string, string>();         (element option:options) {             theaters.put(option.html(), option.attr("value"));         } 

then made adapter spinner:

public class treemapspinadapter extends arrayadapter{     private context context;     private treemap<string, string> treemap;      public treemapspinadapter(context context, int textviewresourceid, treemap<string, string> treemap){         super(context, textviewresourceid, treemap.values().toarray());         this.context = context;         this.treemap = treemap;     }      @override     public int getcount() {         return this.treemap.values().size();     }      @override     public object getitem(int arg0) {         return this.treemap.values().toarray()[arg0];     }      public object getitem(string key) {         return treemap.get(key);     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {         textview label = new textview(context);         label.settextcolor(color.black);         label.settext(treemap.keyset().toarray()[position].tostring());         return label;     }      @override     public view getdropdownview(int position, view convertview, viewgroup parent) {         textview label = new textview(context);         label.settextcolor(color.black);         label.settext(treemap.keyset().toarray()[position].tostring());         return label;     }  } 

then, in our asynctask set spinner so:

treemapspinadapter adapter = new treemapspinadapter(context, android.r.layout.simple_spinner_item, theaters); final spinner spinner = (spinner) ((activity) context).findviewbyid(r.id.spinner1); spinner.setadapter(adapter); 

and call our asynctask so:

new theatergetter().execute(this); 

things called theater , because in case getting list of theater locations.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -