0

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> 

助けてくれてありがとう!!!

4

1 に答える 1

0

画像を追加したいレコードに新しいxmlファイルを作成する必要があると思います。あなたのlistViewようなcategory ListView。私にはあなたの理想があります

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder holder;
     convertView = null;
    holder = new ViewHolder();
    int port = getport.getSingleProtect(position);
    if(port==1){
    //INFLATE YOUR IMAGE
        convertView = inflater.inflate(INFLATE_YOUR_IMAGES, null);
        convertView.setTag(holder);
        .......................




    }else {
        .................
        //INFLATE AS NORMAL
    }


    return convertView;
}
于 2012-06-09T10:09:41.027 に答える