我在解析 Web 响应后获得了 xml 响应,这里是
<NewDataSet>
<Table>
<Restaurant_ID>1705</Restaurant_ID>
<restaurant_name>1947</restaurant_name>
<address>296, Ram Towers, 100 Feet Ring Road, Banashankari, Bangalore</address>
<costoftwo>Approx Rs. 600 for two (without alcohol)</costoftwo>
<rating>3.3</rating>
<timings>11 AM to 11 PM</timings>
<Phone>08026791213</Phone>
<Location_ID>34</Location_ID>
<Location_name>Banashankari</Location_name>
<city_ID>1</city_ID>
<city_name>Bangalore</city_name>
<Cuisine_ID>8</Cuisine_ID>
<Cuisine_name>North Indian</Cuisine_name>
</Table>
我有一个 XML 布局,我需要将上述响应绑定到该布局。我的 XML 布局是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/headerbgcolor"
android:weightSum="1.0"
>
<Button
android:id="@+id/restaurant_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="finishActivity"
android:text="@string/back" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.6"
android:gravity="center"
android:text="@string/restauran_details" />
<Button
android:id="@+id/restaurant_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="@string/home" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/Refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="@string/refresh" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/Restaurant_name"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="@string/restaurant_name"
/>
<TextView
android:id="@+id/Restaurant_add"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="@string/restaurant_address"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="@+id/Restaurant_rating"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_rating"
android:layout_weight="0.1" />
<TextView
android:id="@+id/Restaurant_timings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_timings"
android:layout_weight="0.1" />
<TextView
android:id="@+id/Restaurant_cstfortwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cost_for_two"
android:layout_weight="0.1" />
<TextView
android:id="@+id/Restaurant_cuisine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_cuisine"
android:layout_weight="0.1" />
<TextView
android:id="@+id/Restaurant_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_location"
android:layout_weight="0.1" />
<TextView
android:id="@+id/Restaurant_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_city"
android:layout_weight="0.1" />
</LinearLayout>
<TextView
android:id="@+id/Restaurant_phone"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:text="@string/restaurant_phone"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/footerimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#808000"
android:src="@drawable/btn_bg_cuisine" />
</RelativeLayout>
</LinearLayout>
而且我不知道它是否好,但我正在使用customadapter进行绑定。这是我的自定义适配器。
public class CustomAdapterforRestaurant extends BaseAdapter {
private List<Item> mlist = null;
private Context mcontext;
private LayoutInflater l_Inflater;
public CustomAdapterforRestaurant(Context context, List<Item> lstresponse) {
mlist = lstresponse;
mcontext = context;
l_Inflater = (LayoutInflater) mcontext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolderforcities holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.restaurantdetails, null);
holder = new ViewHolderforcities(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolderforcities) convertView.getTag();
}
holder.restaurant_location.setText(mlist.get(position).getLocation_name());
holder.restaurant_name.setText(mlist.get(position).getRestaurant_name());
holder.restaurant_add.setText(mlist.get(position).getAddress());
holder.restaurant_rating.setText(mlist.get(position).getRating());
holder.restaurant_timings.setText(mlist.get(position).getTimings());
holder.restaurant_cstfortwo.setText(mlist.get(position).getCostoftwo());
holder.restaurant_cuisine.setText(mlist.get(position).getCuisine_name());
holder.restaurant_city.setText(mlist.get(position).getCity_name());
holder.restaurant_phone.setText(mlist.get(position).getPhone());
return convertView;
}
class ViewHolderforcities {
TextView restaurant_name,restaurant_add,restaurant_rating,restaurant_timings,
restaurant_cstfortwo,restaurant_cuisine,restaurant_location,restaurant_city,
restaurant_phone;
public ViewHolderforcities(View base)
{
restaurant_name = (TextView) base.findViewById(R.id.Restaurant_name);
restaurant_add = (TextView) base.findViewById(R.id.Restaurant_add);
restaurant_rating = (TextView) base.findViewById(R.id.Restaurant_rating);
restaurant_timings = (TextView) base.findViewById(R.id.Restaurant_timings);
restaurant_cstfortwo = (TextView) base.findViewById(R.id.Restaurant_cstfortwo);
restaurant_cuisine = (TextView) base.findViewById(R.id.Restaurant_cuisine);
restaurant_location = (TextView) base.findViewById(R.id.Restaurant_location);
restaurant_city = (TextView) base.findViewById(R.id.Restaurant_city);
restaurant_phone = (TextView) base.findViewById(R.id.Restaurant_phone);
}
}
可以一些1请解释我将如何将数据绑定到它。
谢谢拉穆。