我正在尝试动态更改列表视图的图像。但我不知道如何改变它,因为使用setImageResource
不起作用。
这是我的代码片段:
public void onCreate(Bundle savedInstanceState) {
ImageView imgIco=(ImageView)findViewById(R.id.imgIco);
Integer id =getIntent().getExtras().getInt("id");
if(id==2) {
String[] valenzeComposti = getResources().getStringArray(R.array.int_valenze);
// I cannot do this ---------------> imgIco.setImageResource(R.drawable.ico1);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item2,R.id.txtItem, valenzeComposti));
ListView lv2 = getListView();
lv2.setTextFilterEnabled(true);
lv2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v,int position, long id) {
Intent intent = new Intent(getApplicationContext(),InterClassi.class);
intent.putExtra("id",(int)id);
startActivity(intent);
}
});
}
列表视图创建如下 -
The listview xml (R.layout.list_item2)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="5dip">
<ImageView
android:id="@+id/imgIco"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginRight="5dp"
>
</ImageView>
............
</RelativeLayout>
请帮助我..提前谢谢你