I have a simple app that when you click on an image from a GridView, a Dialog pops up with a Button that says View. When you click the Button, I want to view the image that has been clicked in the gallery. I can get this to work without a problem when I have the app navigate to the gallery without a dialog, but I need it to hit a dialog first. The error my LogCat is returning Java.lang.ArrayIndexOutOfBoundsExeption
. Any ideas as to what I need to do to get this to viewing the image? Below is my code.
public void onClick(View v) {
Dialog dia = new Dialog(ViewGrid.this);
dia.setContentView(R.layout.viewimage);
dia.setTitle("What To Do?");
dia.show();
dia.setCancelable(true);
Button button = (Button)dia.findViewById(R.id.viewImage);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = v.getId();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*");
startActivity(intent);
}
});
}
I am getting the error on this line:
intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*");
I figured it out! The below code is the working code. I needed to set my my Id that I got from the view to be from the click of the image, and not from the click of the View button. Thank you everyone for your assistance!
public void onClick(final View viewIt) {
Dialog dia = new Dialog(ViewGrid.this);
dia.setContentView(R.layout.viewimage);
dia.setTitle("What To Do?");
dia.show();
dia.setCancelable(true);
Button button = (Button)dia.findViewById(R.id.viewImage);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = viewIt.getId();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*");
startActivity(intent);
}
});
}