In my ListActivity, I need header and footer views (on the top and bottom of the list) to be used as previous page and next page buttons on my list, respectively, because I want to display only 20 items at a time.
I set my header and foot views by doing:
getListView().addHeaderView(myHeaderView);
getListView().addFooterView(myFooterView);
setListAdapter(adapter);
This works fine, but I need to dynamically remove and add these header and footer views, because some pages of my list may not have a next page button or a previous page button.
The problem is, I cannot call addHeaderView or addFooterView after I have called setListAdapter.
Is there a way around this?
Why not just collapse the header and footer to zero height, or gray out the buttons (even better).
And the best user experience, in my opinion, would be to dynamically load more items when needed (i.e. upon scroll), like the built-in Gmail app does.
Yes, this is a bug or oversight in the ListView component. You can work around this by writing your own WrapperListAdapter that handles adding and removing fixed list items, but I can tell you it's not entirely straightforward to do.
Alternatively — and much easier — you could add a fixed component above or below the ListView where you place the next and previous buttons.
How about reset the adapter at every time you need to add header view, like this way:
ListView.FixedViewInfo headerInfo = getListView().new FixedViewInfo();
headerInfo.isSelectable=false ;
headerInfo.view = feedInfoView;
headerInfos.add(headerInfo);
headerViewListAdapter = new HeaderViewListAdapter(headerInfos,null,adapter);
getListView().setAdapter(headerViewListAdapter);
Related
I am trying to display a expandable list inside Nested Scroll View . The list is dynamic and i get the details from the api, so i cannot set a fixed height.There are lots of other widget below and above the expandable listview. But when i set the height to wrap content only the first item header is shown. I have tried the solutions in the previous question but they are just a workaround and i want it to be the proper way for my production application. Before marking it as duplicate please hear me out. The previous questions asked are very old and since its almost been an decade i decide to raise this issue again hoping that there is an solution currently.
What i want to achieve
What i am getting by setting height to wrap content
I have say 3 images in a view and want to display a list upon selecting any of the images. Upon selecting an image a list shows up adjacent to the image that was selected. Only one list can show at a time, so if a list is visible next to one image and another image is selected a new list is built next to the selected image and the existing list disappears.
The lists are built using arrays.
Should I use listview or listactivity. Or might there be a better approach to doing this.
Thanks,
you can use Recyclerview List for your mentioned problem
The easiest way, according to me, is to make the layout as you want with the images and with listviews and put initially visibility gone on the lists. When a image is clicked make that list visible (setVisibility(View.VISIBLE)) and the other ones gone (setVisibility(View.GONE)).
This is the most straightforward solution.
I want to create some kind of ListView which will be expanding and collapsing after click on one of its item. When item of ListView is expanded show additional data. After I click another one first data collapsing and show actual one. I found one solution (https://github.com/SilenceDut/ExpandableLayout) but I'm thinking that should be other ways to do that without using external library. Am I right ?
P.S sorry for weak english
You can do it using Expandable List View:
Tutorial Link :-http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
Within a NestedScrollView how do you make every Header stay at a specific point while scrolling down in this case right under the Image until another Header comes by while scrolling down which pushes the first Header and gets replaced by the 2nd Header and so on. I hope the image makes sense to what I am trying to accomplish. Thank You!
If you want to achieve this you should not use NestedScrollView instead use a linear layout with Image at the top then a listview with sticky header. I think this will solve your problem
Here is the link for the list you want. https://github.com/emilsjolander/StickyListHeaders
I am trying to create a top bar for my app that shows the users level, coins. So i have an image view that displays the coin icon and a textview that displays the number of coins, if the number gets high it overlaps the image rather than pushing back the image and keeping everything aligned, is there a way to do that?
Without knowing your layout XML this is pure guesswork, but I'm assuming these two views are in a RelativeLayout. If so, add to one of them an attribute like this:
android:layout_toLeftOf="#id/otherViewId"
Options available are layout_toLeftOf layout_toRightOf layout_above and layout_below.
Post your layout XML and I'll update this with a better answer!
If you are using the relative layout then you can use the z-index attribute of views to manage the ordering.