I am new to android and I'am writing my first app with androidstudio.
I have two activities: the first has a bunch of buttons, all sharing the same onClick() event, which starts the second activity. The second activity has a single button. Both layouts are designed with the interactive GUI editor.
I want the button of the second activity to appear similar (but not identical) to the one in the first activity, which was touched. After much research, I succeeded in identifying the drawableLeft of the source button, and pass its name to the second activity, which then sets it to the target button. However, I find this method too limiting and complicated, considering that probably I will need to pass other data like color and so on.
This is what I am doing now: buttons in the first activity have their tag set to the name of the resource for drawableLeft. On the onClick() event, the tag is read and sent to the second activity via putExtra(). The second activity receives the name of the resource, obtains a resourceID via getResources().getIdentifier, creates the drawable via getDrawable(), and finally sets it to the destination via setCompoundDrawablesWithIntrinsicsBounds().
Problems are: 1) I have to set the tag property redundantly for every button in activity 1; 2) I also want to copy other properties like color and who knows what else more - should I stuff everything in the tag?
Finally the question: is there a more straightforward way to get GUI attributes and forward them to a second activity?
Thank you,
linuxfan
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…