简体   繁体   中英

Google Glass : LiveCard in cardScrollView

I am new with GDK, I am trying to show custom card using LiveCard, in a cardScrollView.

Here is my code to create the cardScrollView :

        cardScrollView = new CardScrollView(this);
        LiveCard liveCard;

        List<LiveCard> cardList = new ArrayList<LiveCard>();
        for (int i = 0; i < definitions.size(); i++) {
            liveCard = new LiveCard(this, "LiveCardWord");
            RemoteViews viewCard = new RemoteViews(getPackageName(),R.layout.layout_livecard);

            viewCard.setTextViewText(R.id.wordCard, definitions.get(i).word);
            viewCard.setTextViewText(R.id.typeCard, definitions.get(i).type);

            liveCard.setViews(viewCard);
            cardList.add(liveCard);
        }

        LiveCardScrollAdapter adapter = new LiveCardScrollAdapter(cardList);
        cardScrollView.setAdapter(adapter);
        cardScrollView.activate();
        setContentView(cardScrollView);

and here is my adapter :

public class LiveCardScrollAdapter extends CardScrollAdapter {
private List<LiveCard> mCards;

public LiveCardScrollAdapter(List<LiveCard> cards) {
    mCards = cards;
}

@Override
public int getCount() {
    return mCards.size();
}

@Override
public Object getItem(int position) {
    return mCards.get(position);
}

@Override
public int getPosition(Object arg0) {
    for (int i = 0; i < mCards.size(); i++) {
        if (getItem(i).equals(arg0)) {
            return i;
        }
    }
    return AdapterView.INVALID_POSITION;
}

@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
    return null;
    //      return ((LiveCard) mCards.get(arg0)).getView(); //=> don't know how show view....
}

}

I can't find how to get the view in a LiveCard for the adapter, and if it works, is the the correct way to do it ?

Thanks for your help !

You can't use livecards in a cardscrollview. LiveCards are for making a service and displaying them to the left of the time screen. In a GDK application you use Cards as views.

public View getView(int arg0, View arg1, ViewGroup arg2) {
    return mCards.get(arg0).getView();
}

Check out the example I made awhile back: https://github.com/w9jds/CardScrollView-Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM