Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Card(int suitInput, int rankInput)
- {
- suit = suitInput;
- rank = rankInput;
- faceUp = false;
- text = RankString[rank] + " of " + SuitString[suit];
- idText = "i_" + RankString[rank] + "_of_" + SuitString[suit];
- }
- public static int getImageId(Context context) {
- return context.getResources().getIdentifier("drawable/@+id/" + idText, null, context.getPackageName());
- }
- @Override
- public void onBindViewHolder(CardAdapter.ViewHolder viewHolder, int position)
- {
- //get the data model based on position
- Card card = mCards.get(position);
- //Set item views baased on views and data model
- ImageButton imageButton = viewHolder.cardButton;
- imageButton.setImageResource(card.getImageId(mContext));
- TextView textView = viewHolder.cardText;
- textView.setText(card.text);
- }
- public class MainActivity extends AppCompatActivity {
- Player me;
- Deck deck;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.testdisplay);
- //lookup the recyclerview in activity layout
- RecyclerView rvCards = (RecyclerView) findViewById(R.id.rvCards);
- me = new Player("Dr_StrangeKill");
- deck = new Deck();
- me.hand.add(deck.getCards().remove(0));
- me.hand.add(deck.getCards().remove(0));
- me.hand.add(deck.getCards().remove(0));
- me.hand.add(deck.getCards().remove(0));
- me.hand.add(deck.getCards().remove(0));
- me.hand.add(deck.getCards().remove(0));
- //create adapter passing in sample user data
- CardAdapter adapter = new CardAdapter(this, me.hand);
- //Attach the adapter to the recyclerView to populate items
- rvCards.setAdapter(adapter);
- //Set layout manager to position the items
- rvCards.setLayoutManager(new LinearLayoutManager(this));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement