我不知道“所有这些文件的 xml 文件”是什么意思,但您可以通过 BitmapFactory.decodeResource(getResources(), R.drawable.pictureId) 获取图片并在 ImageView 中显示该位图。
public class MySimpleArrayAdapter extends ArrayAdapter<MyImage> {
private final Context context;
private final ArrayList<MyImage> values;
public MySimpleArrayAdapter(Context context, ArrayList<MyImage> values) {
super(context, R.layout.rowlayout, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(values.get(i).getDesc());
imageView.setImageResource(values.get(position).getImageId());
return rowView;
}
}
public class MyImage{
String desc;
int imageId;
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="22px"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20px" >
</TextView>
</LinearLayout>