Android 使用decodeFile方法加载手机磁盘中的图片文件

package com.example.androidtest;


import java.io.File;
import java.util.ArrayList;
import java.util.List;


import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;




public class MainActivity extends Activity {


private TextView textView1=null;
private Button button1=null;
private ImageView imageView1=null;
private String pathString=Environment.getExternalStorageDirectory().getPath()+"/picture";
private List picturePathList=null;
private int index=0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1=(TextView)findViewById(R.id.textView1);
/*显示下一张图片,如果显示到最后一张,又会从第一张开始显示*/
button1=(Button)findViewById(R.id.button1);
button1.setText("下一张");
button1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
index++;
if(index==(picturePathList.size())){index=0;}
ShowPicture();
}
});
imageView1=(ImageView)findViewById(R.id.imageView1);
picturePathList=new ArrayList();
/*获取磁盘下面的全部图片*/
File pictureDir=new File(pathString);
if(pictureDir.exists()&&pictureDir.isDirectory()){
File[] files=pictureDir.listFiles();
if(files!=null&&files.length>0){
for(int i=0;i


你可能感兴趣的:(android)