I am passing data to a list view to display some restaurant names. Now when I click on an item, I want to start another activity to show more restaurant data. I'm sure how to do this. Do I pass all restaurant data into a bundle through intent object? Or will I just pass the restaurant id and get data in the second activity? In that case, how can I use my restaurant with other activities? In any case, how can I get the data from the restaurant I clicked (only include name of view)?
Any help, welcome the signal!
ListView lv = (ListView) findViewById (R.id.listview); Lv.setAdapter (New ArrayAdapter & lt; string & gt; (this, android.R.layout.simple_list_item_1, restaurantList.getRestaurantNames ())); Lv.setOnItemClickListener (New OnItemClickListener) {Public Zero onItemClick (see AdapterView & LT;?> Parents, see integer status, long ID) {intent I = new intent (Atable.this, RestaurantEdit.class) ; Bundle b = new bundle (); //b.printInt("id ",?); StartActivityForResult (i, ACTIVITY_EDIT);}});
RestaurantList.Java
package org.digitalfarm.atable; Import java.util.ArrayList; Import java.util.list; Public category restaurants list (private list & lt; restaurant & gt; restaurant = new arrelistist & lt; restaurant & gt; (); public list & lt; restaurants & gt; GetRestaurants () {this return.restaurants;} public zero set Restart (list & lt; Restaurant & gt; Restaurant) {this.restaurants = restaurant;} Public list & lt; string & gt; GetRestaurantNames () {List & lt; string & gt; Restaurant- = new Arseau & lt; string & For (gt; i) this.restaurants.size (); i ++) {restaurantNames.add (this.restaurants.get (i) .getName ());} return R Names of Levels;}}
Restaurants. Java
package org.digitalfarm.atable; Public class restaurants {Private IIT; Private string name; Private Float latitude; private float longitude; public int getId () {return.id;} public zero setId (int id) {this.id = id;} public string getName () {this.name;} public zeros setname (string name } {This.name = name;} Get the public float latitat () {this return.latitude; } Public Zero Set Latitude (Float Latitude) {this.latitude = Latitude; } Get a public float () {Return this. } Public Zero Set Length (Float Longitude) {this.longitude = Longitude; }}
You can not access data from other activities. If you need data in that activity which is started by clicking on the item in the list, then it is sent through the message bundle to the new activity.
If you only pass the ID for next activity, then you can reload the restaurant from a database or from the internet but you can not remove it from the list used in the first activity.
> If the restaurant is heavy to make the object then you can apply yourself and attach restaurant list to this application sub-class. Now you can access this list like this:shopList = (YourSubclass) getApplication (). GetRestaurantList ()
This will be the time to recover your memory in your store list, even if the app is in the background and all activities have been stopped.
Comments
Post a Comment