android - How to generate multiple buttons that have the same intent but have another Extra -
im trying generate multiple views in eclipse layoutinflater. button has onclicklistener , works. intent starts , give extra.
but want button keeps own extras. saying first button has extra: number 1 second has 2 , on. @ moment al buttons same extra, number 5. because when try intent in com.example.http wizard says 5
string[] title = { "1", "2", "3", "4", "5" }; layoutinflater layoutinflator = (layoutinflater) getapplicationcontext().getsystemservice(context.layout_inflater_service); linearlayout insertpoint = (linearlayout) findviewbyid(r.id.ll_content); list<view> views = new arraylist<view>(); for(int i=0; i<title.length; i++){ view view = layoutinflator.inflate(r.layout.single_task, null); textview textview = (textview) view.findviewbyid(r.id.tvname); button bstartwizard = (button) view.findviewbyid(r.id.bstartwizard); textview.settext("opdrachtnummer:" + title[i]); titlestring = "opdrachtnummer:" + title[i]; bstartwizard.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { intent = new intent("com.example.http.wizard"); i.putextra("number", titlestring); startactivity(i); } }); view.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); views.add(view); } for(int = 0; i<views.size(); i++){ insertpoint.addview((view) views.get(i)); }
i hope can me it!
button bstartwizard = (button) view.findviewbyid(r.id.bstartwizard);
i think you're having problem here since want generate 5 buttons same button id on xml, onclicklistener try last value assigned button 5, try generate different id's each buttons.
check code on creating buttons, manipulate values
button bstartwizard = (button) inflater.inflate(r.layout.play_game_option_button, layout, false);
Comments
Post a Comment