2012-11-27 47 views
1

好吧,我能夠從我的SD卡加載到ImageView的特定圖像...沒問題。但我需要更進一步,並添加一個按鈕加載下一個圖像(移動/複製/刪除以前的圖像)。我可以添加按鈕等,但是如何在不知道文件名的情況下檢索「下一個」圖像?這是目前的代碼。我本來希望使用Gallery,但它已被棄用,我似乎無法做任何其他工作。謝謝如何從SD卡上一次加載圖像?

package com.demo.ShowSDImages; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class AndroidBitmap extends Activity 
    {private final String imageInSD = "/sdcard/er.PNG"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); 
     ImageView myImageView = (ImageView)findViewById(R.id.imageview); 
     myImageView.setImageBitmap(bitmap); 

    } 
} 

回答

0

我覺得你可以試用一下這裏這個樣本.. Check this link

在這裏,我想下面的代碼,可以幫助你在獲取圖像。

int imageCount = sdcardPath.listFiles().length; 
    for (int count = 0; count < imageCount - 1; count++) { 
    Bitmap bmp = BitmapFactory.decodeFile(sdcardPath.listFiles()[count] 
    .getAbsolutePath()); 

在示例,而不是使用螺紋或定時器使用在按鈕點擊事件

使用showNext()的頂端提供一試相同的邏輯。快樂編碼