0

リストビューの画像を動的に変更しようとしています。しかし、使用が機能しないため、変更方法がわかり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>

助けてください..よろしくお願いします

4

2 に答える 2

0

おそらく、ListAdapter の独自の実装を作成する必要があります。最も一般的な方法は、BaseAdapter を拡張することです。API Demos の List8 は、カスタム ListAdapter を作成するための良い例です。

于 2013-06-01T09:21:21.437 に答える
0

baseadapter クラスを拡張してリソースを listview に動的に渡すことにより、カスタム リスト ビューを作成できます。このリンクを見てください - http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ これがお役に立てば幸いです。

于 2013-06-01T10:05:51.233 に答える