Android 为展开的listView子项设置背景

Android 为展开的listView子项设置背景,android,listview,setbackground,Android,Listview,Setbackground,我在程序中使用了扩展的listView 这是主布局的代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_

我在程序中使用了扩展的listView

这是主布局的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ExpandableListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:choiceMode="singleChoice">
</ExpandableListView>
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_marginLeft="8dp"
android:drawableRight="@drawable/ic_launcher"
android:gravity="left"
android:paddingLeft="32dp"
android:paddingTop="8dp"
android:text="@string/Text"
android:textAlignment="textEnd"
android:textSize="14sp"
android:textStyle="bold" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_launcher"
    android:drawablePadding="5dp"
    android:gravity="center_vertical"
    android:text="@string/hello_world"
    android:textSize="14sp"
    android:textStyle="bold" >
</TextView>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/black" />

 </LinearLayout>
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData();
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,
    groups);
listView.setAdapter(adapter);
listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.red_button));
}
正如您所看到的,我曾经为listView设置背景

listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.red_button));

我想访问孩子们并为他们设置背景。有谁能帮我做这件事吗?

你可以用适配器代码做这件事。你们在哪里给孩子们充气?请你们再解释一下好吗。确切的代码是什么@Manmohanshare u适配器代码在这里..或者如果您有静态bg,那么您可以直接将bg添加到要充气的行。