2

Working from the Glass Scroll Cards demo, I want to be able to modify the text on a card after tapping the card. I've had some luck doing this with card.setText("blah-blah") but for one reason or other, the setting of text doesn't work until I scroll away from the card and then scroll back to the card. There's probably something that I don't understand about the relationship between the CardScrollAdapter, the toView method, and setContentView. Can anyone offer advice (or possibly a small sample of code)? Thanks.

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37

2 Answers2

0

You must notify your adapter when you change information on the card to get it to refresh. For example:

adapter.notifyDataSetChanged()
ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
0

In your activity give your CardScrollView an OnClickListener like this:

        mCardScrollView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            mCardList.get(arg2).setText("changed");
            //must have this next line to see change reflected in glass
            mCardScrollAdapter.notifyDataSetChanged();
        }

    });

Note that telling the adapter that your data has updated is necessary (see code comment).

If you need more code let me know, or if you can provide your code, I can point out what's wrong. I definitely see my card text changed on tap.

A closing thought, I found it a bit confusing that Card taps in this situation are not available to onKeyDown set for KEYCODE_DPAD_CENTER. CardScrollViews in this sense need to be treated like a ListView in Android as seen in my code example.

Mark Scheel
  • 2,963
  • 1
  • 20
  • 23