0

I'm having a fragment that shows the image and the name of my items and below that I want to show a list of comments on that item. However it seems I cannot use a listview inside my Scrollview. People are suggesting to use header for my listview. But I'm very confused since my header is not static and is different for every item ( I have to get and populate the imageview and textview by an http call). Can someone help me with this issue by providing a simple example or link?

I read this Using a ListAdapter to fill a LinearLayout inside a ScrollView layout but I couldn't figure it out.

Community
  • 1
  • 1
Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63
  • Perhaps you could add a layout xml from your app showing the listview inside the scrollview. Even though that would obviously never actually work, it would give us a better picture of what you're trying to achieve. I'd like to know what is in your layout that requires a scrollview. – kris larson Mar 09 '15 at 04:01

3 Answers3

0

use ViewPager as a headerView of listView.

and then manupulate the ViewPager state yourself :(load update show)..

0

If you want a header that scrolls with the list of comments, look at the RecyclerView. You can find many examples and tutorials online. It allows you to create a list of items, but how an item is displayed can change. The RecyclerView.Adapter determines how to display things, so that is where you will want to focus.

They are a number of tutorials out there, so I won't bother copy/pasting code in here.

eimmer
  • 1,537
  • 1
  • 10
  • 29
0

I fixed it this way: I created an xml layout for my listview (list_layout.xml) with id "list" and another xml layout for my header (header_layout.xml). Then in my fragment in onCreateView did this:

 View v = inflater.inflate(R.layout.list_layout, container, false);

    ListView listView= (ListView) v.findViewById(R.id.list);
    View header = inflater.inflate(R.layout.header_layout,listView, false);
    listView.addHeaderView(header, null, false);
    adapter = new Adapter...
    listView.setAdapter(adapter);

    //lets say you have a text view in your header. This is how you set it
    //pay attention how used **header** NOT v as the view
    Name_textview=(TextView) header.findViewById(R.id.photo_number);
Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63