1
我正在处理可扩展列表视图。我需要根据我的数据库值在childview(child_row)的imageview中显示不同的图像。我试图设置图像,但没有任何作品。可扩展列表视图的自定义childrow
对此有何帮助?在此先感谢....
ExpandableListActivity.java
public class ExpList extends ExpandableListActivity
{
String parent_node[];
String custom_child[][][][];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
SimpleExpandableListAdapterWithEmptyGroups expListAdapter =
new SimpleExpandableListAdapterWithEmptyGroups(
this,
createGroupList(),
R.layout.group_row,
new String[] { "colorName" },
new int[] { R.id.groupname },
createChildList2(),
R.layout.child_row,
new String[] { "name", "number", "date", "time"},
new int[] { R.id.name, R.id.number,R.id.date, R.id.time}
);
setListAdapter(expListAdapter);
// I tried all following methods to put different image in imageview, but not working.
LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.child_row, null);
ImageView img_call = (ImageView)layout.findViewById(R.id.img_call_icon);
img_call.setBackgroundResource(R.drawable.skype);
Drawable d = getResources().getDrawable(R.drawable.skype);
img_call.setBackgroundDrawable(d);
img_call.setImageResource(R.drawable.skype);
img_call.setImageDrawable(d);
}
}
child_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img_call_type"
android:src="@drawable/incoming_call"
android:layout_width="40px"
android:layout_height="40px"/>
<TextView
android:id="@+id/space"
android:layout_width="10px"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:textSize="14px"
android:layout_width="115px"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/number"
android:textSize="14px"
android:layout_width="115px"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/date"
android:textSize="14px"
android:layout_width="115px"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/time"
android:textSize="14px"
android:layout_width="115px"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- This is imageview in which I need to display diffrent images -->
<ImageView
android:id="@+id/img_call_icon"
android:layout_width="40px"
android:layout_height="40px"
android:clickable="true"
android:onClick="onClickHandler"/>
</LinearLayout>
</LinearLayout>
公众查看getChildView做了我的把戏,谢谢为你的答案.. – 2012-03-29 10:00:02