为多列设置listview的背景图像

时间:2011-07-18 10:28:31

标签: android listview

我必须为listview设置背景图像。不为每一行设置图像。要设置整个屏幕的背景图像&列表视图加载时选择单选按钮。这意味着应该选择第一个选项

这是我的代码。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sales_routes);  // **Added edited**
    ArrayList<Object> routeList = getWmRoute();
    ArrayList<String> routhPath = new ArrayList<String>();
    for(int i = 0; i<routeList.size();i++){
        routhPath.add(((WMRoute) routeList.get(i)).getDescription());
    }
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_two_column, R.id.FROM_CELL, routhPath));
    ListView list=getListView();
}

我的xml文件是(list_two_column.xml)

<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="4dip" 
    android:paddingBottom="6dip"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
     <!--android:background="@drawable/wallpaper" -->

    <RadioButton android:id="@+id/radioButton1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </RadioButton>

    <TextView android:id="@+id/FROM_CELL" 
          android:layout_width="70dip"
          android:layout_height="wrap_content" 
          android:layout_weight="1" />

</LinearLayout>

新添加 - sales_routes.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView 
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dip"
        android:layout_marginRight="6dip"
        android:dividerHeight="2dip"
        android:background="@drawable/wallpaper" />
</LinearLayout>

目前其显示列表,问题是图像背景图像

enter image description here

要求

  1. 在列表视图加载时选择单选按钮。这意味着第一个选项应该选择

1 个答案:

答案 0 :(得分:0)

在values文件夹中创建一个样式主题,并向其添加一个windowBackground项,并将该样式添加到布局xml