-2

i am doing a project using android studio in which once user logins,images of the books in their cart should be displayed. But different users have different number of books in their account like one user may have one book in their account and other may have three books in their account. I can't do this using static xml as i don't know how many image view to put in xml design.so, if their are two books in user account, only two image view should be displayed.My friend suggested me to use stack overflow and list view. so , how can i do this??

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Usha
  • 1
  • 1
  • `... suggested me to use stack overflow and list view` StackOverflow is both this community and an error. To "use stack overflow" you need to show the code where you're stuck. Anyway, I'd suggest to use an ExpandableListView, so you can expand each user (or expand them all at once) and show their books. – Phantômaxx Apr 10 '17 at 06:52
  • 1
    Hello and welcome to Stackoverflow! Please read [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) – Douwe de Haan Apr 10 '17 at 09:31

1 Answers1

0

You'll have to use ListView or RecyclerView which is advanced version of ListView. To do so Create two XML files.

  1. One that will hold the ListView. Something like this <LinearLayout><ListView/></LinearLayout>.
  2. And other will have the contents of ListView, which in your case are Images.so create <LinearLayout><ImageView/></LinearLayout>.

with these two XML files you don't have to care about the number of images/books each user have.

In your main activity create a ListViewAdapter and assign this adapter to your first XML layout containing the ListView.

Now in you AdapterClass getView() Method, inflate the second layout and you can access the imageview. Here you'll set the Image to your ImageView.

deejay
  • 572
  • 4
  • 18