0
我可以通過此代碼進入我的自定義目錄,該代碼顯示我目錄中的圖像列表,現在我想要的是當我單擊圖像列表時打開這些圖像。從列表視圖中獲取圖像onlistitemclick
private void getDir(String dirPath) {
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if (!dirPath.equals(root)) {
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for (int i = 0; i < files.length; i++) {
File file = files[i];
path.add(file.getPath());
if (file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.explorernew, item);
setListAdapter(fileList);
}
File file;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File imgFile = new File(root+"/20150424_173923.jpg");
// TextView stxt = (TextView) findViewById(R.id.textView2);
// stxt.setText(List.get(position));
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
}
}
我已經硬編碼我的imgfile作爲顯示圖像的圖像名稱。我要動態地改變我的選擇
感謝另一件事是真的幫助:) – Brendom
歡迎您:) –