Prashanth
Prashanth

Reputation: 341

Get Drawable of a button on Another Activity in Android

I Have a button with a top drawable image, onclicking the button a intent is created i want to pass this drawable to the intent. How to do it pls help me out thanks in advance..

Button

My Button

Image to be showed on next activity

Image to be showed on next activity

Upvotes: 0

Views: 473

Answers (2)

erik
erik

Reputation: 4958

Assuming that your buttons are all atrological signs, and that you know what image resource you are using for each, why don't you just assign all your buttons the same onClick listener, and use a switch case to determine which sign it is.

public void onClick(View v) {
    Intent i = new Intent(this, yourSecondActivity.class);      
    switch(v.getId()){
        case R.id.ariesBtn:
            i.putExra("sign", "aries");
            break;

        case R.id.cancerBtn:
            i.putExtra("sign", "cancer");
            break;

    }

    startActivity(i);
}

Then in your other activity check for extras "sign" and act accordingly

Upvotes: 2

ygrunin
ygrunin

Reputation: 345

Try this:
@drawable/filename

or post the code to better undertastand

Upvotes: 0

Related Questions