我不知道你是什么意思的“所有他们的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>
你问关于如何自己存储图片吗?或者如何引用图片及其路径(不使用XML)。您需要使用某些东西,最好是已存储所有配方名称的任何东西,也可以将它们的路径存储在资源文件夹(无论是XML还是一些简单的数据库)中。 – Wrightboy 2013-03-08 22:43:44
我在问两个问题。我可以将它们存储在资源文件夹中,只需将它们的路径从列表视图打开到屏幕即可。或者我必须为所有图像构建xml页面。 – curiousprogrammer 2013-03-09 00:26:31