Friday, 15 July 2011

Generalized Android Activity -



Generalized Android Activity -

i new android programming. question have list (listview) of 8 restaurant headings. upon clicking of of these, new page (activity) start containing menu , details of restaurant. understand implementing 8 activities wasteful have general restaurant detail activity.

now figuring out how display info out in efficient way. have far implemented helps me send message across other activity according restaurant selected. how can send big chunks of information:

----mainactivity.java------

string [] restaurants = {"abc","def"....}; int position_act; list.setonitemclicklistener(new adapterview.onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, int position, long id){ position_act=position; customactivity(view); } }); public void customactivity(view view) { intent intent = new intent(this, restaurantdetails.class); intent.putextra(message, "you clicked restaurant: " + restaurants[position_act]); startactivity(intent); }

--generalrestaurant.java----

intent intent = getintent(); string msg = intent.getstringextra(foodactivity.message); textview tt1 = (textview) findviewbyid(r.id.tt1); tt1.settext(msg);

you shouldn't passing lots of information. model info should in instances of restaurant class. can maintain instances in arraylist in singleton. write getter singleton returns restaurant instance , phone call restaurantdetails activity using sent (maybe want create uuid). finally, when activity dies, should save restaurant info singleton raw xml file or , read in when app starts again.

android android-activity

No comments:

Post a Comment