android - How do we pass different value to another activity by selecting choice-based table row in a table -
i have created table containing dynamic table rows. each table row contain 5 textview containing data's region name ,regioncode ,target etc. have implemented table row onclicklistner,so user can select table row view more specific data in activity. problem each table row contain must diffrent regioncode passed activity. how pass activity.i tried using string array show null point exception.
this code
// if branchflag zonal
else if(branchflag.equals("z")) { final list<namevaluepair> details = new arraylist<namevaluepair>(1); details.add(new basicnamevaluepair("branchcode", branchcode)); details.add(new basicnamevaluepair("branchflag", branchflag)); details.add(new basicnamevaluepair("finyr",finyear)); details.add(new basicnamevaluepair("month", month_number)); log.d("month_num", month_number); response = apc.posturl(retrieve_branch_mis_details_link, details); log.d("**************", retrieve_branch_mis_details_link + details); log.d("retrieve_mainmis_details_link", response); try { jsonobject jsonobject = new jsonobject(response); jsonarray = jsonobject.getjsonarray("result"); errorflag = jsonobject.getstring("errorflag"); errormsg = jsonobject.getstring("errormsg"); if (errorflag.equals("n")) { // adding 4 data sections table row textview label_product = new textview(mainmis.this); label_product.setid(0); label_product.settext(" region "); label_product.settextcolor(color.white); tr_head.addview(label_product);// add column table row here textview label_target = new textview(mainmis.this); label_target.setid(0);// define id must unique label_target.settext(" target "); // set text header label_target.settextcolor(color.white); // set color label_target.setpadding(5, 5, 5, 5); label_target.setgravity(5); // set padding (if required) // label_target.setwidth(10); tr_head.addview(label_target); // add column table row here textview label_achievement = new textview(mainmis.this); label_achievement.setid(0); label_achievement.settext(" achievement"); label_achievement.settextcolor(color.white); label_achievement.setpadding(5, 5, 5, 5); label_achievement.setgravity(5); // label_achievement.setwidth(50); tr_head.addview(label_achievement); textview label_shortfall = new textview(mainmis.this); label_shortfall.setid(0); label_shortfall.settext(" shortfall"); label_shortfall.settextcolor(color.white); label_shortfall.setpadding(5, 5, 5, 5); label_shortfall.setgravity(5); // label_achievement.setwidth(50); tr_head.addview(label_shortfall); textview label_ranking = new textview(mainmis.this); label_ranking.setid(0); label_ranking.settext(" ranking "); label_ranking.settextcolor(color.white); label_ranking.setpadding(5, 5, 5, 5); label_ranking.setgravity(5); tr_head.addview(label_ranking); // add table row the main table layout fetched @ start tl.addview(tr_head, new tablelayout.layoutparams( linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent)); textview[] textarray = new textview[jsonarray.length()]; tablerow[] tr_head1 = new tablerow[jsonarray.length()]; try { numberformat nf = numberformat.getinstance(); nf.setmaximumfractiondigits(2);// set need int = 0; int j = 0; (i = 0; < jsonarray.length(); i++) { jsonobject jsonobj = jsonarray.getjsonobject(i); // jsonobject productdata = product.getjsonobject("product"); // string productdescription = product.getstring("achievementper"); decimalformat df = new decimalformat("#"); incomeamount = ((jsonobj.getstring("achievementsum"))); excshort = ((jsonobj.getstring("excshort"))); string excshort1 = excshort.replace(",", "."); double excshort2 = double.parsedouble(excshort1); log.d("excshort, replace ,", excshort1); log.d("excshort in point format,", excshort1); targetamount = ((jsonobj.getstring("targetsum"))); //added sooraj regions = ((jsonobj.getstring("regionname"))); zonename=((jsonobj.getstring("zonalname"))); log.d("achievementper123", string.valueof((((excshort))))); //create tablerows tr_head1[i] = new tablerow(mainmis.this); tr_head1[i].setclickable(true); tr_head1[i].setid(i + 1); if ((i % 2) == 0) { tr_head1[i].setbackgroundcolor(color.ltgray); } else { resources resource = getapplicationcontext().getresources(); tr_head1[i].setbackgroundcolor(resource.getcolor(r.color.white_overlay)); } // tr_head1[i++].setbackgroundcolor(color.yellow); tr_head1[i].setlayoutparams(new tablelayout.layoutparams( linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent)); // here create textview dynamically textarray[i] = new textview(mainmis.this); //modified
//
textarray[i].setid(i + 111); textarray[i].settext(" " + regions); textarray[i].settextcolor(color.black); textarray[i].setpadding(5, 5, 5, 5); tr_head1[i].addview(textarray[i]); textarray[i] = new textview(mainmis.this); textarray[i].setid(i + 111); textarray[i].settext(string.valueof(targetamount)); textarray[i].settextcolor(color.black); // textarray[i].setwidth(10); textarray[i].setpadding(5, 5, 5, 5); textarray[i].setgravity(5); tr_head1[i].addview(textarray[i]); textarray[i] = new textview(mainmis.this); textarray[i].setid(i + 111); textarray[i].settext(string.valueof(incomeamount)); textarray[i].settextcolor(color.black); // textarray[i].setwidth(10); textarray[i].setpadding(5, 5, 5, 5); textarray[i].setgravity(5); tr_head1[i].addview(textarray[i]); textarray[i] = new textview(mainmis.this); textarray[i].setid(i + 111); textarray[i].settext(string.valueof(excshort )); if (excshort2 > 0) { textarray[i].settextcolor(color.blue); } else { textarray[i].settextcolor(color.red); } // textarray[i].setwidth(120); textarray[i].setpadding(5, 5, 5, 5); textarray[i].setgravity(5); tr_head1[i].addview(textarray[i]); //added branch ranking textarray[i] = new textview(mainmis.this); textarray[i].setid(i + 111); textarray[i].settext(string.valueof(rgn_ranking)); textarray[i].settextcolor(color.black); // textarray[i].setwidth(10); textarray[i].setpadding(5, 5, 5, 5); textarray[i].setgravity(gravity.center|gravity.bottom); tr_head1[i].addview(textarray[i]); tl.setvisibility(view.visible); l2.setvisibility(view.gone); l3.setvisibility(view.gone); if (tr_head1.length > 0) { tl.addview(tr_head1[i], new tablelayout.layoutparams( linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent)); length = string.valueof(tr_head1.length); log.d("length of array", string.valueof(length)); //make table row onclickable tr_head1[i].setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent a=new intent(mainmis.this,regionmis.class); bundle extras = a.getextras(); startactivity(a); } }); } } if ((i == 0)) { log.d("no rows display **", ""); tl.setvisibility(view.gone); l2.setvisibility(view.visible); l3.setvisibility(view.gone); //toast.maketext(mainmis.this, "no data display", toast.length_long).show(); } } catch (jsonexception e) { e.printstacktrace(); log.d("error...", e.getmessage().tostring()); } } else { tl.setvisibility(view.gone); l2.setvisibility(view.gone); l3.setvisibility(view.gone); l4.setvisibility(view.visible); errormsgedit.settext(errormsg); } } catch (exception ex) { ex.printstacktrace(); log.d("error...error..", ex.getmessage().tostring()); } }
the simplest way this
intent intent = new intent(mainmis.this, regionmis.class); intent.putextra("extra_region_code", regioncode); startactivity(intent)
Comments
Post a Comment