监听器重名
按钮的监听OnClickListener
AlertDialog.Builder builder的监听也是OnClickListener
两个会冲突,所以AlertDialog.Builder builder的监听,要写成全名new DialogInterface.OnClickListener(){...}
例如
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String[] strs = { "拍照上传", "相册选取" };
builder.setItems(strs, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
// Intent camera = new
// Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent camera = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(camera, 1);
break;
case 1:
Intent picture = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(picture, 2);
break;
}
}
});
builder.create().show();
}
按钮的监听OnClickListener
AlertDialog.Builder builder的监听也是OnClickListener
两个会冲突,所以AlertDialog.Builder builder的监听,要写成全名new DialogInterface.OnClickListener(){...}
例如
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String[] strs = { "拍照上传", "相册选取" };
builder.setItems(strs, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
// Intent camera = new
// Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent camera = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(camera, 1);
break;
case 1:
Intent picture = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(picture, 2);
break;
}
}
});
builder.create().show();
}