hi,
I'm passing data to a ListView to display some restaurant names. Now when clicking on an item I'd like to start another activity to display more restaurant data. I'm not sure about how to do it. Shall I pass all the restaurant data in a bundle through the intent object? Or shall I just pass the restaurant id and get the data in the other activity? In that case, how can I access my restaurantList from the other activity? In any case, how can I get data from the restaurant I clicked on (the view only contains the name)?
Any help, pointers welcome!
Thanks
Jul
ListView lv= (ListView)findViewById(R.id.listview);
lv.setAdapter( new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,restaurantList.getRestaurantNames()));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(Atable.this, RestaurantEdit.class);
Bundle b = new Bundle();
//b.putInt("id", ? );
startActivityForResult(i, ACTIVITY_EDIT);
}
});
RestaurantList.java
package org.digitalfarm.atable;
import java.util.ArrayList;
import java.util.List;
public class RestaurantList {
private List<Restaurant> restaurants = new ArrayList<Restaurant>();
public List<Restaurant> getRestaurants() {
return this.restaurants;
}
public void setRestaurants(List<Restaurant> restaurants) {
this.restaurants = restaurants;
}
public List<String> getRestaurantNames() {
List<String> restaurantNames = new ArrayList<String>();
for (int i=0; i<this.restaurants.size(); i++) {
restaurantNames.add(this.restaurants.get(i).getName());
}
return restaurantNames;
}
}
Restaurant.java
package org.digitalfarm.atable;
public class Restaurant {
private int id;
private String name;
private float latitude;
private float longitude;
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public float getLatitude() {
return this.latitude;
}
public void setLatitude(float latitude) {
this.latitude = latitude;
}
public float getLongitude() {
return this.longitude;
}
public void setLongitude(float longitude) {
this.longitude = longitude;
}
}