我有一個從數據庫中通過的動態圖像數組。我只是在第一個屏幕上顯示圖像縮略圖,並希望顯示同一圖像陣列的全屏。問題是我想將整個動態數組傳遞給下一個屏幕。其實我知道如何在java中使用首選項。但我不知道如何通過變量或其他東西傳遞整個數組。任何想法將不勝感激。將圖像陣列傳遞到下一個屏幕
public class MerchantDetails extends GLCityActivity implements OnClickListener {
public static MerchantDetails instance;
private Gallery gallery;
private ImageView imView;
String Header, contentName;
DBManager gDatabase = new DBManager(this);
private ArrayList<Multimedia> mm;
private ImageViewAdapter iva;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Translucent);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.details);
instance = this;
initActivity(instance, " ");
try {
gDatabase.createDataBase();
} catch (IOException e) {
throw new Error("Unable to create database");
}
try {
gDatabase.openDatabase();
} catch (SQLiteException sqle) {
throw sqle;
}
settingLayout();
}
public void settingLayout() {
SharedPreferences preferences = getSharedPreferences(
Constants.DEFAUL_SHARE_DATA, 0);
Header = preferences.getString("SubName", "");
headerTxt = (TextView) findViewById(R.id.templateTopTitleTView);
headerTxt.setText(Header);
gallery = (Gallery) findViewById(R.id.gallery);
if (mm.isEmpty()) {
gallery.setVisibility(gallery.INVISIBLE);
} else {
gallery.setAdapter(iva);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,
int position, long id) {
SharedPreferences preferences = getSharedPreferences(
Constants.DEFAUL_SHARE_DATA, 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("ImagePosition", mm.get(position) + "");
editor.putInt("ImageLength", mm.size());
Intent viewer = new Intent(instance, GalleryViewer.class);
startActivityForResult(viewer, 0);
if (editor.commit()) {
}
}
});
}
}
private class ImageViewAdapter extends ArrayAdapter<Multimedia> {
private ArrayList<Multimedia> items;
public ImageViewAdapter(Context context, int textViewResourceId,
ArrayList<Multimedia> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.image_list, null);
}
Multimedia info = items.get(position);
if (info != null) {
ImageView imView = (ImageView) v
.findViewById(R.id.rowlistIconIView);
String name = info.thumbnail;
String[] test = gDatabase.split(name, ".");
int resID = getResources().getIdentifier(test[0], "drawable",
getPackageName());
Log.v("Log", name + ";" + resID + ";" + test[0] + ";");
try {
imView.setImageResource(resID);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
return v;
}
}
}
編輯: @Jeremy愛德華茲,感謝您的回覆。我試圖按照你的建議去做,但我發現這個錯誤,而我編碼。我嘗試使用putExtra(String name,int [] value)但錯誤說Intent類型的putExtra(String name,boolean value)方法不適用於參數(String,Multimedia)。其實我已經從自動提示框中選擇了putExtra(String name,int [] value)。想知道它是如何突然變回(String name,int [] value)的。請檢查我的代碼如下。 private ArrayList<Multimedia> mm; viewer.putExtra("ImagePosition",mm.get(position));
viewer.putExtra(String name,int[] value)
「任何想法都將被賞識(d)。」爲了更好地幫助您:1)發佈[SSCCE](http://pscode.org/sscce.html)2)提出具體問題。 3)在問題中添加一個問號(?)。 – 2011-03-23 05:35:39