1

我有一个由布局 list_item_new.xml 定义的列表,其中有一个 imageView 和 2 个 textView。ImageView 是这样定义的

 <ImageView
        android:id="@+id/listimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"

        android:gravity="center"

        android:src="@drawable/users2"
    />

我在 3 个不同的屏幕上使用相同的 ListView。现在我想要的是这个 imageView 上的图像对于所有 3 个屏幕应该是不同的。我正在尝试更改为这样的图像

LayoutInflater inflater = (LayoutInflater) this.getSystemService
             (Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.list_item_new, null);
        listimg=(ImageView)ll.findViewById(R.id.listimage);
        listimg.setImageResource(R.drawable.office);

office.png 是可绘制的图像。

整个代码正在执行,但图像没有改变。请告诉我应该怎么做才能更改图像。我在 onCreate 活动方法中编写此代码,之后我将数据分配给列表

谢谢

4

1 回答 1

1

看这堂课

public class Adapter extends SimpleAdapter{

public Adapter(Context context, List<? extends Map<String, String>> data,
        int resource, String[] from, int[] to) {
    super(context, data, resource, from, to);

}
@Override
public View getView(int position, View convertView, ViewGroup parent){
 View row = convertView;
 if (row == null) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    row ll = inflater.inflate(R.layout.list_item_new, null);
    listimg=(ImageView)ll.findViewById(R.id.listimage);
    listimg.setImageResource(R.drawable.office);

    textView=(TextView)ll.findViewById(R.id.<textViewID>);
    textView.setText("Hello");
 }

 return row;
}

}
于 2013-02-20T09:31:23.857 回答