Intents, bundles

0

My question is the following as it can be done to send images in intents using bundles. A serious example I have an activity in which pressing an Imagebutton happens to the next in which I want to put the image that had the button. But instead of a single button I have 4 in an acitvity.

public void btn_hombre(View view) {

    if (hombre.isChecked() == true && hombre_bajo.isClickable()) {
        Intent intent = new Intent(GeneroActivity.this,holaActivity.class);
        intent.putExtra("hombre_alto", R.drawable.hombre_alto);
        startActivity(intent);

    }else if (hombre_normal.isClickable()) {
        Intent intent = new Intent(GeneroActivity.this, IMCActivity.class);
        intent.putExtra("hombre_pequeño", R.drawable.hombre_pequeño);
        startActivity(intent);

    }else if (hombre_sobrepeso.isClickable()) {
        Intent intent = new Intent(GeneroActivity.this, IMCActivity.class);
        intent.putExtra("hombre_sobrepeso", R.drawable.hombre_sobrepeso);
        startActivity(intent);

    }else if (hombre_sobrepeso1.isClickable()) {
        Intent intent = new Intent(GeneroActivity.this, IMCActivity.class);
        intent.putExtra("hombre_sobrepeso1", R.drawable.hombre_sobrepeso1);
        startActivity(intent);
    }

Something like that I send to the second activity.

The detail is not how to receive it in the second activity to activate a conditional to show the corresponding image in the imageview. as selected. Thanks in advance for the help.

    
asked by Jaime Santamaria 02.10.2018 в 08:46
source

1 answer

0

The image is in your project, you do not need to pass the image, just a reference to it to know what it is.

public void btn_hombre(View view) {
    String imgsel;
    if (hombre.isChecked() == true && hombre_bajo.isClickable()) {
        imgsel = "hombre_alto";
    }else if (hombre_normal.isClickable()) {
        imgsel = "hombre_pequeño";
    }else if (hombre_sobrepeso.isClickable()) {
        imgsel = "hombre_sobrepeso";
    }else if (hombre_sobrepeso1.isClickable()) {
        imgsel = "hombre_sobrepeso1";
    }

    Intent intent = new Intent(GeneroActivity.this,holaActivity.class);
    intent.putExtra("btnselect", imgsel);
    startActivity(intent);
}

And in the destination of the intent you pick up the bundle, where you already have the name of the image. From the name you identify the image and associate it with the ImageView where you want to show it.

Bundle bundle = getIntent().getExtras(); 
String imagen = bundle.getString("btnselect");
    
answered by 02.10.2018 в 09:08