Hi,
I'm just starting with Android and can't find how to display a list in my activity.
I get some restaurant data from a web service and I'd like to show the results in a list.
The activity, the restaurant class and the layout main.xml are shown below.
How can I display, for instance, the list of the restaurant names in the ListView 'list' of my layout?
thank you
Jul
public class Atable extends ListActivity {
RestaurantList restaurantList;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Here I set restaurantList
//Now how can I display, for example, the list of the names of the restaurants
}
main.xml
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search" />
<EditText android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noresults"/>
</LinearLayout>
</LinearLayout>
Restaurant list class
package org.digitalfarm.atable;
import java.util.List;
public class RestaurantList {
private List<Restaurant> restaurants;
public List<Restaurant> getRestaurants() {
return restaurants;
}
public void setRestaurants(List<Restaurant> restaurants) {
this.restaurants = restaurants;
}
}
Restaurant class
package org.digitalfarm.atable;
public class Restaurant {
private String name;
private float latitude;
private float longitude;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getLatitude() {
return latitude;
}
public void setLatitude(float latitude) {
this.latitude = latitude;
}
public float getLongitude() {
return longitude;
}
public void setLongitude(float longitude) {
this.longitude = longitude;
}
}