android - how to access inner class variable in outer class method in java -
i want access inner class hashmap variable in outer class method means item selected listener of spinner. have hashmap declare inside inner class , assigning value in hashmap inside inner class method. accessing hashmap value using key in setonitemselectedlistener outer class got null value in hashmap.
made hashmap static in outer class , put value in inner class , again access outer class listener again got null value. if having soltion please tell me. little bit confused here .i don't know wrong. please have solution.
following outer , inner class
public class projectdetailactivity extends sherlockactivity { // declare hashmap. hashmap<string, string> phaseidkv = new hashmap<string, string>(); @override protected void oncreate(bundle savedinstancestate) { new loadphasedata().execute(projid); //create variable of inner class final projectdetailactivity.loadphasedata inner = new projectdetailactivity().new loadphasedata(); //listener phase spinner projspinnerphase.setonitemselectedlistener((onitemselectedlistener) new onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { int id = projspinnerphase.getselecteditemposition(); ++id; string p_id= inner.phaseidkv.get(id); //here want access inner class hashmap value log.v("hashmap value","-"+inner.phaseidkv.get(id));//getting null toast.maketext(getapplicationcontext(),"item-"+id+" item2"+item+"p_id"+p_id, toast.length_long).show(); } }); } private class loadphasedata extends asynctask<string, void, void> { @override protected void doinbackground(string... params) { ----- jsonarray phasedata = new jsonarray(jsonpphaselist); string [] phaseno = new string[jsonpphaselist.length()]; string phase; string phaseid1; if (phasedata.length() >0) { for(int =0;i<phasedata.length();i++){ jsonobject jophasefromja = phasedata.getjsonobject(i); phase = jophasefromja.getstring("phase_no") phaseid1 = jophasefromja.getstring("phase_id"); phaseidkv.put(phase,phaseid1); } } return null; }
problem phaseno[index] not initialized. null. key null
also
hashmap<string, string> phaseidkv = new hashmap<string, string>();
a hashmap key value pair strings
//phaseno string array. for(int =0;i<phasedata.length();i++){ phase = jophasefromja.getstring("phase_no") phaseid1 = jophasefromja.getstring("phase_id"); phaseidkv.put(phase ,phaseid1); }
to get
int id = projspinnerphase.getselecteditemposition(); ++id; string p_id= phaseidkv.get(string.valueof(id));// convert int string id should match phase key put in hash map
if want access p_id everywhere in class declare outerclass variable.
Comments
Post a Comment