一个activity中有图片按钮,我想把图片一个一个的加载到外部。这意味着除了第一个之外,所有的图片按钮一开始都是不可见的。单击按钮后,我应该能够加载图像,并且在按钮上加载图像后,应该会显示下一个按钮。我为第一个按钮实现了这一点,但无法为其余按钮做到这一点。这是我的代码。
public class MainActivity extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
ImageButton a, b, c, d, e, f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a = (ImageButton) findViewById(R.id.imageButton1);
b = (ImageButton) findViewById(R.id.imageButton2);
c = (ImageButton) findViewById(R.id.imageButton3);
d = (ImageButton) findViewById(R.id.imageButton4);
e = (ImageButton) findViewById(R.id.imageButton5);
f = (ImageButton) findViewById(R.id.imageButton6);
a.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageButton a = (ImageButton)findViewById(R.id.imageButton1);
a.setImageBitmap(BitmapFactory.decodeFile(picturePath));
b.setVisibility(b.VISIBLE);
}
}