0

I've only ever used adapters for lists so I don't even know if this is possible.

I have a stack of views (the UI is like looking down on a deck of cards in real life. So it's not a listview like your contacts list) created programmatically in a for-loop. Each view has an imageView and a textView. Is it possible to hook these views to an adapter so I don't have to worry about keeping a reference to each one?

EDIT:

There seems to be some confusion, which I apologize for. I'm not looking for a way to create the stacked view. I have that. It looks like the picture I posted below. What I need to do is keep track of the data that each view uses, so if the user pops the top card off the view, the card below it displays the correct image and text

here's a visual example of what my view looks like (I'm not actually making a deck of cards, but this is the best example I can think of):

enter image description here

Psest328
  • 6,575
  • 11
  • 55
  • 90
  • Why is it not a list ? If the elements are so different from each other (completely different layout for each item), writing "Each view has an imageView and a textView" is a bit odd. – 2Dee Feb 03 '15 at 17:03
  • They're not different, but it's not presented in a list. It's presented like looking down on a deck of cards – Psest328 Feb 03 '15 at 17:04

3 Answers3

0

What you are describing sounds like a different permutation of a ListView. What I would suggest is just creating a custom list view that shows the list in the format you want. Overriding drawing and layout of the list items.

This would allow you to still use an adapter to handle the data set in a similar way without reinventing the wheel.

Update: Use the AbsListView

Whose job specifically is:

Base class that can be used to implement virtualized lists of items. A list does not have a spatial definition here. For instance, subclases of this class can display the content of the list in a grid, in a carousel, as stack, etc.

Elliott
  • 539
  • 4
  • 14
  • the UI is like looking down on a deck of cards in real life. So it's not a listview like your contacts list. – Psest328 Feb 03 '15 at 17:05
  • So what you are talking about is the `GridView` but that follows a similar pattern as `ListView` so you would extend `AbsListView` which allows you to have similar implementations as the other two but with the correct UI implementation that you need. http://developer.android.com/reference/android/widget/AbsListView.html – Elliott Feb 03 '15 at 17:10
  • aaahhhhh, now you're talk'n!! Going to look into that now – Psest328 Feb 03 '15 at 17:12
  • Just looked, and unfortunately this isn't what I need. I don't need to create the stack of items, I've got that. What I need is to keep track of the items on the stack, so if I pop the top card off the stack, the next card shows the correct image and text – Psest328 Feb 03 '15 at 17:20
0

Sounds like you want to use cards through the material design. However google warns against of such use, since stacking information like that is a bad practice.

Marcin D
  • 918
  • 7
  • 14
  • You want to keep your views somewhere, sounds like a back button problem. Maybe this can help. http://stackoverflow.com/questions/18305945/how-to-resume-fragment-from-backstack-if-exists – Marcin D Feb 03 '15 at 17:40
  • The link you provided is regarding fragments, I'm talking about views – Psest328 Feb 03 '15 at 17:41
0

I can see AbsListView was suggested, so if you're going down that route I suggest you to check the RecyclerView it's based on a more modern API, more flexible, etc, etc.

The RecyclerView does all the view recycling, and a LayoutManager is added to it that put those recycled views on the screen.

You can find this API here https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html

the support library already comes with LinearLayoutManager, GridLayoutManager, StaggeredGridLayoutManager, you might be able to find others developed by the community.

Budius
  • 39,391
  • 16
  • 102
  • 144
  • well, in that case you can do much simpler. Remember simpler is always better. Just an ArrayList with your data or maybe a Queue. And just an integer point to `where` in your stack you are. For every MotionEven of removing card you trigger a `cardRemoved` interface that picks the next item. – Budius Feb 03 '15 at 17:31