Google Glass:cardScrollView中的LiveCard

时间:2014-07-11 13:10:05

标签: android google-glass google-gdk

我是GDK的新手,我正在尝试使用LiveCard在cardScrollView中显示自定义卡。

这是我创建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);

这是我的适配器:

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....
}

}

我找不到如何在LiveCard中获取适配器的视图,如果它有效,是否正确的方法呢?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您不能在cardscrollview中使用livecards。 LiveCards用于制作服务并将其显示在时间屏幕的左侧。在GDK应用程序中,您将卡片用作视图。

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

查看我做了一段时间的示例:https://github.com/w9jds/CardScrollView-Example