I am trying to build multiple card views that I can scroll on my google glass. The data that I want to display are data of objects stored in an arraylist.
I do not know why I am getting a black screen on my glass by using the following codes. tried to follow the documentation on google but theres not result. Forgive me as I am new to google glass.
Activity Class
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
mCardScroller = new CardScrollView(this);
mCards = new ArrayList<CardBuilder>();
for(int i=0; i<dataSet.size(); i++) {
CardBuilder card = new CardBuilder(this,Layout.COLUMNS);
card.setText(dataSet.get(i).getInfo());
mCards.add(card);
}
mCardScroller.setAdapter(new danceAdapter(mCards));
setContentView(mCardScroller);
}
danceAdapter Class
public class danceAdapter extends CardScrollAdapter {
private ArrayList<CardBuilder> mCards;
public danceAdapter(ArrayList<CardBuilder> cards){
this.mCards = cards;
}
@Override
public int getCount() { return mCards.size(); }
@Override
public Object getItem(int i){ return mCards.get(i); }
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
return mCards.get(i).getView();
}
@Override
public int getPosition(Object o) { return this.mCards.indexOf(o); }
}
Could there be something wrong with my main activity class? Please help with code snippets. Much Appreciated.
You forgot to activate your ScrollView. Also as a side note, you shouldn't make your cards outside of the adapter and before everything. Not only is that loop inefficient (runs the .size every iteration) the amount of memory to store the views is not necessary. Try doing something like this:
But if you want to do a custom view instead of CardBuilder that is supported. You just need to inflate and return the view inside the getView method like you usually would.