我想创建一个列表视图,在 onCreate() 方法中初始化时立即将图像添加到某些字段,我不知道该怎么做。
这是我的 onCreate() 方法的必要部分:
((ListView) findViewById(android.R.id.list)).setClickable(true);
for(int i=0; i<num_enter; i++){
adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current", "image"}, new int[] {R.id.text1, R.id.text2, R.id.lockImage});
setListAdapter(adapter);
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("name", name[i]);
SetSql getport = new SetSql(this);
getport.open();
int port = getport.getSingleProtect(i);
getport.close();
if(port==1){
//THIS IS WHERE I WANT TO SET THE IMAGE
temp.put("current", Integer.toString(current[i]));
}else{
temp.put("current", Integer.toString(current[i]));
}
listItems.add(temp);
adapter.notifyDataSetChanged();
}
}else{
((ListView) findViewById(android.R.id.list)).setClickable(false);
adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current"}, new int[] {R.id.text1, R.id.text2});
setListAdapter(adapter);
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("name", "You have no enteries yet!");
temp.put("current", "");
listItems.add(temp);
adapter.notifyDataSetChanged();
}
这是我的custome_row_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/lockImage"
/>
<TextView android:id="@+id/text1"
android:textSize="25dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView android:id="@+id/text2"
android:textSize="25dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
谢谢你的帮助!!!