0
我想創建一個列表視圖,立即在onCreate()方法初始化時將圖像只添加到某些字段,我不知道如何做到這一點。Android - 在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>
感謝您的幫助!
我不是真的有熟悉並且列表視圖,和我幾乎可以肯定,我可以修改自己的代碼將圖像添加到列表視圖的某些項目。我只是不知道如何。 – arielschon12