Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <declare-styleable name="PokerButton">
- <attr name="spade" format="integer" />
- <attr name="club" format="integer" />
- <attr name="heart" format="integer" />
- <attr name="diamond" format="integer" />
- </declare-styleable>
- <declare-styleable name="PokerButtonSuit">
- <attr name="suit" format="integer" />
- </declare-styleable>
- </resources>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
The top 4 work fine in this code:
Using java Syntax Highlighting
- public PokerButton(Context context, AttributeSet attrs){
- super(context, attrs);
- this.ctx = context;
- this.bg = this.getBackground();
- setOnClickListener(this);
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PokerButton);
- this.suit = new Suit[] { new Suit(a.getDrawable(R.styleable.PokerButton_spade)), new Suit(a.getDrawable(R.styleable.PokerButton_club)), new Suit(a.getDrawable(R.styleable.PokerButton_heart)), new Suit(a.getDrawable(R.styleable.PokerButton_diamond)) };
- a.recycle();
- }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
But, this code does not seem to work:
Using java Syntax Highlighting
- public class PokerButtonSuit extends Button implements View.OnClickListener {
- private Context ctx = null;
- private int suit;
- public PokerButtonSuit(Context context, AttributeSet attrs, int defStyle){
- super(context, attrs, defStyle);
- }
- public PokerButtonSuit(Context context, AttributeSet attrs){
- super(context, attrs);
- ctx = context;
- setOnClickListener(this);
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PokerButtonSuit);
- this.suit = a.getInteger(R.styleable.PokerButtonSuit_suit, 0);
- a.recycle();
- }
- public PokerButtonSuit(Context context){
- super(context);
- }
- public void onClick(View v){
- this.setText(this.suit);
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
I did notice in my research that there is a TypedArray.getInteger() and a TypedArray.getInt(). No idea what the difference is. All I want to do is pass an integer through XML so I can differentiate which object I am dealing with inside the class I made. Any advice would be greatly appreciated. Thank you.


