ListeView inside a ViewFlipper - android-widget

I have nested 2 ListView widgets inside a ViewFlipper:
<ViewFlipper android:id="#+id/flipper" android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="#+id/bikeListView" android:layout_height="wrap_content" android:layout_width="fill_parent" />
<ListView android:id="#+id/bikeComponentsListView" android:layout_height="wrap_content" android:layout_width="fill_parent" />
</ViewFlipper>
I put a log at getView() method at my custom ListAdapter classes for the 2 ListView widgets and I discovered that when I move to next or previous view in ViewFlipper getView it is called even if ListView is not visible. For example, when I move from first ListView to the second one, getView() for the first one is called, although the second ListView is displayed.
Is this the expected behaviour? My intention is to use ViewFlipper and onFling to move back and forth in ViewFlipper and add many ListView inside ViewFlipper programmatically.
Thanks for reading my question.

I ran into the same issue and found that it's because your layout_height is set to wrap_content....see this post for more info:
http://www.anddev.org/view-layout-resource-problems-f27/multiple-calls-of-getview-in-arrayadapter-t16595.html

Related

.net maui ListView don't scroll to added item when binded to ObservableCollection

I have a maui ListView binded to ObservableCollection, I expect when I add a new element to the collection my ListView automatically scrolls to that new Item.
But instead my ListView doesn't update itself,
I added a CollectionChanged event on my code behind (trying to achieve this), and make a manually scroll when item added but no when I run
LstItems.ScrollTo(e.NewItems[e.NewItems.Count - 1], ScrollToPosition.End, false);
My ListView goes to the end but it rebuilds all the entire ListView as you can see at Adding New Item to ListView
I tryed changing CachingStrategy to: RecycleElement, RetainElement but same result.
I tryed using ScrollToPosition to MakeVisible But same result.
I tryed setting to false the Animation parameter of ScrollTo But same result.
My questions:
There is a way to make my ListView automatically scrolls to the
new added item? If not:
There is a way to manually move to the new
added item wihtout the UI effect of rebuild the entire ListView?
You can try to use CollectionView to achieve this.
You can scroll to the last item by using the following code:
mCollectionView.ScrollTo(myViewModel.Items.Count - 1, animate: true);
For more about this, you can check: Scroll to End.

Flutter - How to Rebuild the SiverList without also rebuilding the SliverAppBar?

If I can't use a FutureBuilder inside a CustomScrollView how I can rebuild only the SliverList without also rebuilding the SliverAppBar?
I'm doing an app similar to Youtube, so like Youtube I have several buttons with the categories inside a ListView in the SliverAppBar area (Example in the image below) and a SliverList with the videos, but currently everything inside the CustomScrollView is rebuilt when I click on a category button. And the ListView inside the SliverAppBar always goes back to position 0 after rebuilding it instead of staying in the same position like Youtube.
The ideal result would be just rebuilding the SliverList. Or at least keep the ListView position (on the SliverAppBar) in the same position that was before rebuilding. How that can be done?

Scroll Parent ListView when nested ListView.builder is updated

I have a ListView with, say, PostItems being generated with ListView.builder.
Each PostItem MAY have comments on it. So each PostItem has a nested ListView.builder to show comments for that PostItem.
User can add a Comment to the nested ListView. However, UX would like to scroll to that newly added Comment in the nested ListView. Nested Listview shrinkwrap is true, with NeverScrollable Physics. When nested Comment listview expandeds with new Comment, it's off screen and I want to scroll down to it.
ListView.builder -> PostItem -> Nested ListView.builder
However, my assumption is that I need to make the parent ListView scroll down but how do I know where to scroll to when it's the Nested listview that has grown in height.
I can't share code due to the project but any theological thoughts or ideas would be a great help!
Thanks
I can see that, based on your description, we can access the index of that particular ListView. Thus, I would suggest you to use this package to achieve what you want:
scroll_to_index

How to Build All elements of sliverlist once?

I'm making a screen with comments section that has comments & their sub comments.
I use ScopedModel for managing state of the screen.
The data for comments is in a List<-model->
and for subcomments are inside the model->List<-model->.
this data is in ScopedModel.
I build a sliverList with SliverChildBuilderDelegate so it builds only widgets that are on screen.
Every comment (current_comment) has a reply button, that, after typing, adds a comment model at the end of (current_comment)model-> List<-model->
and calls notifyListener() on the ScopedModel
Now the newly added subcomment has a tag that identifies it as a new comment.
What I want:
I want that the screen scrolls to the newly added subcomment.
What I tried:
Since the newly added subcomment can be identified by a tag, I add a GlobalKey to that comment widget when its built. and then after build is complete, I scroll to that position using the offset obtained from GlobalKey added to it.
My Problem :
Since the SliverList builds elements which are visible to screen only, the newly added comment is far below the parent comment (because reply comment button is on the parent comment only) and isn't built yet. so the builder hasn't attached the GlobalKey to it yet.
Now, how do I auto-scroll to it?
Since key isn't attached to it yet, how do I locate its position & scroll to it?
Suggest me a way to either build all elements of the Sliverlist at once so the key may be attached to the element or another strategy so to auto-scroll to the newly added comment.
First solution is to set shrinkWrap property as true to the listview so it renders all children at once, and hence GlobalKey is assigned to it.
Second solution is to use a column instead, which will lead to rendering all children at once.
Both solutions are not suitable when there are too many children.

Strange issue when I using GtkScrolledWindow in glade

I want to wrap a listbox widget into a scrolled widget, then I find the GtkScrolledWindow, however, I could not drag and drop a GtkListBox into GtkScrolledWindow. I also tried right click the GtkListBox, select Add Parent then Scrolled Window like the following snapshot.
But, I could make it work by manual modify the glade ui file.
So I want to know Why and How to do it in glade.
José Fonte's answer is right, I need to wrap the content into a viewport first, then make the viewport as a child of scrolledWindow.