Empty ListView inside ScrollView as two Fragments - android

I want to have ScrollView Inside a Fragment that contains a TabHost as you can see from the screen-shot
it's composed by two sections:
Header: in my case it's an image, I want this section to scroll
TabHost: contains three Fragments one of them is a ListView
What I have tried ?
I tried to create a scroll view and a list view inside the TabHost, everything is fine for the two first tabs, but in the third one which is a ListView, the items are not displayed.
After some research, I figured out that we can't have a ListView inside a ScrollView.
So what is the best approach to create a view like described here is a screen-shot of what I want to create:

In fact there's a way to implement ListView in ScrollView. But with this solution, ListView acts like a LinearLayout in memory.
btw: I used it before and working nice, saves the day.

Related

Best practice to reuse RecyclerView layout in other places

I have a Fragment which contains a RecyclerView to display a list of items in a feed. However, an individual item might be opened in another Fragment with the same layout it has in the RecyclerView.
What would be the best practice for this scenario? Could/should I create a separate Fragment for the item and use it somehow in the RecyclerView?
Well, when you create RecyclerView in the first fragment, you also create layout for the item you want to display. In the other, fragment you can just include the layout of the item. I don't think it can get more simple than that.
My practice is, i try to identify items that repeat itself and i try to create general layouts, for example, layout with title and subtitle and the use this layout in RecyclerView or just include it. Good thing here is that RecyclerView allows you to have different layouts and instead of drawing views or including it (if there are more view in fragment that i have created), i just add it to one RecyclerView.

scrollView linearlayout and listview

I'm doing an android app, and I just want to have an scrollable layout, but inside of this layout I want to put some textView and 2 listView, and this is my problem, the listView.
I need to include this 2 listview on the layout and this is obligatory need to be scrollable, and I googling and all I found is negative.
how can I put 2 listview on scrollView?? is not possible? and if its right what can i do? Which is the alternative that I have? I really desesperated because I spend all day!!
con someone say me an example of this?
really thanks!
ListViews shouldn't be placed inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all get handled by the parent ScrollView. However you can add views you want to be scrolled to the ListView as headers or footers.

Is it possible to accommodate a scroll view and a ListView in one activity?

I'm creating an app that will support Android 2.2 and above.
In that I have 10 edit texts and 10 text views that I accommodate in a scroll view.
And I wanted to Accommodate a list view also inside the same activity.
Is it possible to accommodate the whole in a single activity?
You can have a ListView in a ScrollView, but that is a bad design. Even Eclipse will throw a warning. Moreover the behavior will be different, because ListView already has its own ScrollView.
So the only solution could be to have a Fixed length ScrollView and a ListView in some other Layout(Linear/Relative).
Yes, it is possible however it's not recommended enclose a list view inside a scroll view since list view has already implemented scrolling and as android documentation says it won't work. What you could do is to create a fragments, and in one fragment place a views that you want to have inside a scroll view and on other fragment - your list view. Then put two fragments inside an activity.

How do I add a ViewPager as the top item in my ListView

I have a vanilla "News" app, where the main page is a ListView that scrolls vertically with a list of articles (thumbnail, title..etc). This works just fine, but now I want to add a horizontal article/photo rotator as the top item in that list. I don't really care if it's technically in the list or not, but it should scroll up/off the screen when the list is dragged...etc. I assume(d) it should be in the list, but am quite new to Android and don't know if there's a better solution.
After an entire day of searching around, I'm still empty-handed - don't know how to add it or even if it's the right method. I'm using a ViewPager for my gallery view (when they click a photo), and that seems to be working fine...but that's the entire view... and this one already has an adapter that populates the listView... I hope I'm just over-complicating something.
TLDR:
1) Can I add a ViewPager as top item in a ListView?
2) How would one go about doing it?
3) Is there a better solution?
Note: android:minSdkVersion="8" android:targetSdkVersion="15"
You can use addHeaderView() from the ListView API to set a header. It can be any View, so also a ViewPager. I think you'll have to add it programmatically. Set the height of it correctly though.
i'm not sure i understand your question. ViewPager is a view like any other, so in your ListView's adapter's getView() method, return a view that contains a ViewPager.
ViewPager is a topic in itself, so if your problem is that you don't understand ViewPager, read these links,
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
if you are using API level 8, you should use the ViewPager and friends from the compatibility package.
that all being said, i wonder if you will have trouble putting a scrollable view inside a scrollable view. i know ViewPager contains code to pass off any gestures to child views if it decides it cannot handle them. i can't say if ListView has the same smarts.

Merging ViewFlipper with ListView

What I'm trying to do is to have horizontal ViewFlipper and Listview, both with custom ArrayAdapters, inside LinearLayout which would be vertically scrollable on whole screen.
1) Tried adding ViewFlipper as a ListView header but then I can't use GestureListener since ArrayAdapter takes control over it like it's ListView item.
2) Tried putting them together inside LinearLayout but ViewFlipper's position is fixed and ListView is scrollable inside rest of the screen.
3) Trying with MergeAdapter but it can't handle swipe gesture on it's first element (ViewFlipper), it always returns ViewFlipper's item position.
Here's the picture to clarify what I'm trying to make. Top Stories is ViewFlipper and Latest Posts is ListView. And they both scroll vertically. Ignore bottom tabs and ActionBar as they are static (nonscrollable).
You've got your work cut out for you.
Here are two approaches:
1) Set the view flipper as the first row in the List view. Its a special case. Not as a header, but as a regular row.
2) Use a scroll view, and do not use the list view at all. You may have performance problems if your data for the list view is a large number of items.
Take a look at the ViewPager from the Android Compatibility Library it does what you need

Categories

Resources