I'm trying to use layout files instead of the cardbuilder. Currently I have my first card inflated. This would be the card that is being used as card when you start the application.
Now when you scroll to the left I want to show my next card. However I can't seem to find how I would achieve this when I'm using layout files. Does anyone have experience with this? This for a immersion btw.
this is the code I used to show my first card.
@Override
public View getView(int i, View view, ViewGroup viewGroup)
{
View convertView;
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.farmhouse_main, viewGroup);
return convertView;
}
Edit
After looking at the code that @EntryLevelDev submitted I wrote my own CardScrollAdapter
I did this in a way to make sure that you only have to make changes in one method when you want to insert or delete a certain card.
My adapter
public class MainAdapter extends CardScrollAdapter {
private List<CustomCard> mCards;
private LayoutInflater inflate;
public MainAdapter(List<CustomCard> cards, LayoutInflater inf)
{
this.mCards = cards;
this.inflate = inf;
}
@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) {
int card = mCards.get(i).getContent();
view = inflate.inflate(card, viewGroup, false);
return view;
}
@Override
public int getPosition(Object o) {
return this.mCards.indexOf(o);
}
}
my CustomCard class
public class CustomCard {
public int content;
public CustomCard(int content)
{
this.content = content;
}
public int getContent() {
return content;
}
}
Then in my activity I made a method to add the cards to the list and called this method in my onCreate() before setting the adapter.
public void CreateCards()
{
mCards.add(new CustomCard(R.layout.card_simple_layout));
mCards.add(new CustomCard(R.layout.main_farmhouse));
}
Would this be considered good practice or should I be going a different way? Please keep in mind that this is just a sample project and I used the project EntryLevelDev used to play around with it.