I click on the image and it lets me select one from the gallery, but when I select it it doesn't change. I know I'm missing a part of the code, could someone help me with it? Thank you!
MainActivity:
public class MainActivity extends AppCompatActivity {
private static final int PHOTO_SELECTED = 1;
ImageButton fotoH;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fotoH = (ImageButton) findViewById(R.id.pruebah);
fotoH.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, PHOTO_SELECTED);
}
});
}
}
I have finally solved it. I leave the code here
You are accessing through the method defined in the view to perform the intent,
as an option you can define in each view the index of the element through the Tag,
This way you can get the index of the selected photo:
Although it is important to comment that what you do must be done through a Custom Intent Chooser, to open the photo in an application that can manipulate your content type, it would be like this: