开发者

android UI - adding a new class

I would think this should be a relatively easy question to answer, but I'm brand new to android development and so not sure where else to turn.

I have a simple layout (relative currently) for my main Activity. I want to create an object (a card for a card game) that will have all of the necessary properties for that card (value, suit, etc). I have images for all of those cards in m开发者_如何学Goy drawable folder.

For the sake of testing, I created a card.xml file in my layout folder and "hardcoded" in the background for one card.

My question is, now that I have an xml file with the layout for my card, how should I plug this into an object that contains info about that card and then how do I pull that object onto my main scene? Should I create the card object as another activity and use setContentView() to reference the card.xml in the layout folder? As I said, I'm just starting android development and not entirely sure how Activities work. Assuming this is the correct method, how would I then pull this second activity onto my main scene?

TIA


Welcome to android programming!

What you should do is to create a custom component by creating a new class that extends a view (like View or your root element in card.xml) and set it to use ur xml file. You can find a guide here: http://developer.android.com/guide/topics/ui/custom-components.html

In this custom component you'll be able to save everything you need. To use your component, just use it in an xml file like you would do with a button or a textview, you can find out how to in the link i posted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜