我不知道你是什麼意思的「所有他們的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