Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd really recommend using the xml to do this memory game but if you dont want to the following should work, note I cant test it out as I dont have any of the required images or anything</p> <pre><code>class MainActivity extends Activity implements OnItemSelectedListener { GridView cardsGridView; private ArrayAdapter&lt;CardButton&gt; cardsAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); cardsGridView = new GridView(getBaseContext()); setContentView(cardsGridView); CardButton[] cards = getListOfRandomCards(); cardsAdapter = new ArrayAdapter&lt;CardButton&gt;(this, android.R.layout.simple_spinner_item, cards) { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = new ImageView(getBaseContext()); ImageView view = (ImageView) convertView; CardButton card = getItem(position); int ImageResource; if (card.IsSelected()) { ImageResource = card.getCardImage(); } else { ImageResource = R.drawable.default_card_image; } view.setImageResource(ImageResource); return view; } }; cardsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); cardsGridView.setAdapter(cardsAdapter); cardsGridView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { // To change body of implemented methods use File | Settings | File Templates. CardButton card = (CardButton) parent.getItemAtPosition(position); card.SetSelected(true); ImageView imageView = (ImageView) view; imageView.setImageResource(card.getCardImage()); } @Override public void onNothingSelected(AdapterView&lt;?&gt; parent) { // To change body of implemented methods use File | Settings | File Templates. } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload