Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListView ItemsSource refreshing problems in Windows and Android, Button double activating before DisplayAlert popup #6377

Closed
DavidCarKc opened this issue Apr 21, 2022 · 7 comments · Fixed by #6902
Assignees
Labels
area-controls-listview ListView and TableView fixed-in-6.0.312 Look for this fix in 6.0.312! p/0 Work that we can't release without platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@DavidCarKc
Copy link

Description

    • Windows can't display more than 60ish item in ListView, trying to put 65 objects list as ItemsSource crashes Windows app with
      System.Runtime.InteropServices.COMException: '0x88000FA8'
      On android app this does not happen and I tried 80 objects in list and it showed them all.
  1. Setting a list as ItemsSource works fine first time, then if I try to add new objects to the list and then again setting the list (now with more objects) as ItemsSource the ListView will not change and will not show new objects.
    This can be fixed by setting ItemsSource=null and then setting the new list as ItemsSource then it will show new objects.

  2. On Android having 1 object shown then adding another and showing both will crash the app, same if you first show 5 and add another 5 and try to show all 10 the app will crash. BUT if you first show 15 objects and then add one or more and refresh it won't crash and will show all the objects. It is a bit strange that it will take like 1 minute to show them, they just aren't rendered to the screen because after refreshing if you swipe up-down they will show in like 3 seconds but if you don't touch the screen they won't show for a minute.
    Debugger reports: Exception Unhandled
    Java.Lang.IllegalStateException: ''

  3. Also if you doubleclick very fast on the button it will activate twice ( the counter will increase by 2 which it shouldn't) there is like a 100ms delay between the click and DisplayAlert popup which blocks the rest of the app to the user where you can do another click and it will be processed by its event function. I tested it on windows and android and I can do it on both.

Steps to Reproduce

Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.2.0 Preview 4.0

  1. create new maui project MauiListViewTestRC1v172P4.MainPage
    Use the provided MainPage.xaml and MainPage.xaml.cs

//MainPage.xaml

<ScrollView>
    <VerticalStackLayout >          
        <Button 
            Text="Click me"
            FontAttributes="Bold"
            SemanticProperties.Hint="Counts the number of times you click"
            Clicked="OnCounterClicked"
            HorizontalOptions="Center" />
        <Label 
            Text="NUMBER OF OBJECTS: "
            SemanticProperties.HeadingLevel="Level1"
            FontSize="Medium"
            HorizontalOptions="Start" 
            x:Name="LabelCounter"/>
        <ListView      
            x:Name="listView1">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout VerticalOptions="Center">
                            <Label Text="{Binding ID, StringFormat= 'ID: {0}'}"
                           FontAttributes="Bold"/>
                            <Label Text="{Binding Name, StringFormat='NAME: {0}'}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </VerticalStackLayout>
   
</ScrollView>

//MainPage.xaml.cs
namespace MauiListViewTestRC1v172P4;

public partial class MainPage : ContentPage
{
int count = 0;
List smallList = new List();
public MainPage()
{
InitializeComponent();
}

private async void OnCounterClicked(object sender, EventArgs e)
{
	count++;
	LabelCounter.Text = "NUMBER OF OBJECTS: " + count.ToString();
	var obj = new smallObject();
	obj.ID = count;
	obj.Name = count.ToString();
	smallList.Add(obj);
	var answer = await DisplayAlert("ListView1", "Refresh ListView now?", "Yes", "No");
//	if (answer) { listView1.ItemsSource = smallList; } // THIS WILL REFRESH THE LIST ONLY FIRST TIME AFTER THAT IT WON'T WORK
	if (answer) { listView1.ItemsSource = null; listView1.ItemsSource = smallList; }
	//listView1.ItemsSource = smallList;
}

}

public class smallObject
{
public int ID { get; set; }
public string Name { get; set; }
}

MauiListViewTestRC1v172P4.zip

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Tesed on windows 10x64 PC , Android 9.0 Phone

Did you find any workaround?

No response

Relevant log output

No response

@DavidCarKc DavidCarKc added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Apr 21, 2022
@Redth Redth added this to the 6.0.300 milestone Apr 21, 2022
@v-longmin v-longmin added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Apr 22, 2022
@v-longmin
Copy link

Verified repro on Android12.0 - API31 & Windows10 with VS 17.3.0 Preview 1.0 [32414.199.main]. Repro project:
MauiApp3.zip

@kzryzstof
Copy link

I am porting a WPF application to MAUI. I am reusing the view-models and I have been having this issue since I started the port few weeks ago and it seems fairly random (i.e. i.e. I restart the application and it works).

I have updated Visual Studio Community 2022 to the latest 17.2 Preview 5.0.

image

@davidortinau davidortinau added p/0 Work that we can't release without fatal labels May 1, 2022
@Redth
Copy link
Member

Redth commented May 4, 2022

@rmarinho it seems there are more cases where views are recycled but not properly removed from their parent (at least on android).

[yname.mauiapp3] runtime.cc:655] Pending exception java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.addViewInner(android.view.View, int, android.view.ViewGroup$LayoutParams, boolean) (ViewGroup.java:5235)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.addView(android.view.View, int, android.view.ViewGroup$LayoutParams) (ViewGroup.java:5064)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.addView(android.view.View, int) (ViewGroup.java:5004)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.addView(android.view.View) (ViewGroup.java:4976)
[yname.mauiapp3] runtime.cc:655]   at android.view.View crc64e1fb321c08285b90.ListViewAdapter.n_getView(int, android.view.View, android.view.ViewGroup) (ListViewAdapter.java:-2)
[yname.mauiapp3] runtime.cc:655]   at android.view.View crc64e1fb321c08285b90.ListViewAdapter.getView(int, android.view.View, android.view.ViewGroup) (ListViewAdapter.java:100)
[yname.mauiapp3] runtime.cc:655]   at android.view.View android.widget.HeaderViewListAdapter.getView(int, android.view.View, android.view.ViewGroup) (HeaderViewListAdapter.java:224)
[yname.mauiapp3] runtime.cc:655]   at android.view.View android.widget.AbsListView.obtainView(int, boolean[]) (AbsListView.java:2387)
[yname.mauiapp3] runtime.cc:655]   at android.view.View android.widget.ListView.makeAndAddView(int, int, boolean, int, boolean) (ListView.java:2067)
[yname.mauiapp3] runtime.cc:655]   at android.view.View android.widget.ListView.fillDown(int, int) (ListView.java:793)
[yname.mauiapp3] runtime.cc:655]   at android.view.View android.widget.ListView.fillSpecific(int, int) (ListView.java:1504)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.ListView.layoutChildren() (ListView.java:1802)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.AbsListView.onLayout(boolean, int, int, int, int) (AbsListView.java:2184)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(boolean, int, int, int, int) (SwipeRefreshLayout.java:689)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void crc64e1fb321c08285b90.ListViewRenderer.n_onLayout(boolean, int, int, int, int) (ListViewRenderer.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void crc64e1fb321c08285b90.ListViewRenderer.onLayout(boolean, int, int, int, int) (ListViewRenderer.java:71)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.LayoutViewGroup.n_onLayout(boolean, int, int, int, int) (LayoutViewGroup.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.LayoutViewGroup.onLayout(boolean, int, int, int, int) (LayoutViewGroup.java:63)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void androidx.core.widget.NestedScrollView.onLayout(boolean, int, int, int, int) (NestedScrollView.java:1944)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.MauiScrollView.n_onLayout(boolean, int, int, int, int) (MauiScrollView.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.MauiScrollView.onLayout(boolean, int, int, int, int) (MauiScrollView.java:63)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.ContentViewGroup.n_onLayout(boolean, int, int, int, int) (ContentViewGroup.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void crc6452ffdc5b34af3a0f.ContentViewGroup.onLayout(boolean, int, int, int, int) (ContentViewGroup.java:71)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void crc640ec207abc449b2ca.ShellPageContainer.n_onLayout(boolean, int, int, int, int) (ShellPageContainer.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void crc640ec207abc449b2ca.ShellPageContainer.onLayout(boolean, int, int, int, int) (ShellPageContainer.java:54)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.RecyclerView$LayoutManager.layoutDecoratedWithMargins(android.view.View, int, int, int, int) (RecyclerView.java:9878)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(androidx.recyclerview.widget.RecyclerView$Recycler, androidx.recyclerview.widget.RecyclerView$State, androidx.recyclerview.widget.LinearLayoutManager$LayoutState, androidx.recyclerview.widget.LinearLayoutManager$LayoutChunkResult) (LinearLayoutManager.java:1689)
[yname.mauiapp3] runtime.cc:655]   at int androidx.recyclerview.widget.LinearLayoutManager.fill(androidx.recyclerview.widget.RecyclerView$Recycler, androidx.recyclerview.widget.LinearLayoutManager$LayoutState, androidx.recyclerview.widget.RecyclerView$State, boolean) (LinearLayoutManager.java:1591)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(androidx.recyclerview.widget.RecyclerView$Recycler, androidx.recyclerview.widget.RecyclerView$State) (LinearLayoutManager.java:668)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2() (RecyclerView.java:4309)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.RecyclerView.dispatchLayout() (RecyclerView.java:4012)
[yname.mauiapp3] runtime.cc:655]   at void androidx.recyclerview.widget.RecyclerView.onLayout(boolean, int, int, int, int) (RecyclerView.java:4578)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void androidx.viewpager2.widget.ViewPager2.onLayout(boolean, int, int, int, int) (ViewPager2.java:527)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(androidx.coordinatorlayout.widget.CoordinatorLayout, android.view.View, int) (HeaderScrollingViewBehavior.java:148)
[yname.mauiapp3] runtime.cc:655]   at boolean com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(androidx.coordinatorlayout.widget.CoordinatorLayout, android.view.View, int) (ViewOffsetBehavior.java:43)
[yname.mauiapp3] runtime.cc:655]   at boolean com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(androidx.coordinatorlayout.widget.CoordinatorLayout, android.view.View, int) (AppBarLayout.java:2122)
[yname.mauiapp3] runtime.cc:655]   at void androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(boolean, int, int, int, int) (CoordinatorLayout.java:953)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.setChildFrame(android.view.View, int, int, int, int) (LinearLayout.java:1829)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.layoutVertical(int, int, int, int) (LinearLayout.java:1673)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.onLayout(boolean, int, int, int, int) (LinearLayout.java:1582)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void androidx.drawerlayout.widget.DrawerLayout.onLayout(boolean, int, int, int, int) (DrawerLayout.java:1263)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.setChildFrame(android.view.View, int, int, int, int) (LinearLayout.java:1829)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.layoutHorizontal(int, int, int, int) (LinearLayout.java:1818)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.onLayout(boolean, int, int, int, int) (LinearLayout.java:1584)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.setChildFrame(android.view.View, int, int, int, int) (LinearLayout.java:1829)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.layoutVertical(int, int, int, int) (LinearLayout.java:1673)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.LinearLayout.onLayout(boolean, int, int, int, int) (LinearLayout.java:1582)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.layoutChildren(int, int, int, int, boolean) (FrameLayout.java:332)
[yname.mauiapp3] runtime.cc:655]   at void android.widget.FrameLayout.onLayout(boolean, int, int, int, int) (FrameLayout.java:270)
[yname.mauiapp3] runtime.cc:655]   at void com.android.internal.policy.DecorView.onLayout(boolean, int, int, int, int) (DecorView.java:784)
[yname.mauiapp3] runtime.cc:655]   at void android.view.View.layout(int, int, int, int) (View.java:22844)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewGroup.layout(int, int, int, int) (ViewGroup.java:6389)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewRootImpl.performLayout(android.view.WindowManager$LayoutParams, int, int) (ViewRootImpl.java:3470)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewRootImpl.performTraversals() (ViewRootImpl.java:2938)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewRootImpl.doTraversal() (ViewRootImpl.java:1952)
[yname.mauiapp3] runtime.cc:655]   at void android.view.ViewRootImpl$TraversalRunnable.run() (ViewRootImpl.java:8171)
[yname.mauiapp3] runtime.cc:655]   at void android.view.Choreographer$CallbackRecord.run(long) (Choreographer.java:972)
[yname.mauiapp3] runtime.cc:655]   at void android.view.Choreographer.doCallbacks(int, long) (Choreographer.java:796)
[yname.mauiapp3] runtime.cc:655]   at void android.view.Choreographer.doFrame(long, int) (Choreographer.java:731)
[yname.mauiapp3] runtime.cc:655]   at void android.view.Choreographer$FrameDisplayEventReceiver.run() (Choreographer.java:957)
[yname.mauiapp3] runtime.cc:655]   at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:938)
[yname.mauiapp3] runtime.cc:655]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
[yname.mauiapp3] runtime.cc:655]   at void android.os.Looper.loop() (Looper.java:223)
[yname.mauiapp3] runtime.cc:655]   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7656)
[yname.mauiapp3] runtime.cc:655]   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
[yname.mauiapp3] runtime.cc:655]   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:592)
[yname.mauiapp3] runtime.cc:655]   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:947)

@rmarinho
Copy link
Member

rmarinho commented May 5, 2022

@Redth this happens with ListView, works fine with CollectionView .

@DavidCarKc any reason why you aren't using CollectionView? I tested your sample with collectionview on android and it works as expected.

Related with your point 2nd point, this is not a bug, it's how MAUI works, you are adding items to the collection and setting the collection multiple times, but the collection object isthe same, so it won't fire that the ItemsSOurce change since it's in fact the same object (List).
Works when you use null because you are removing the ItemsSource (set null) then assigning the ItemsSource again.
One way to go around this is use a ObservableCollection, then you can add items only assign it once as ItemsSOurce and as you add items the UI will update with the new items.

Can you also give me some code example for your 3rd point?! I think if it's the exception we see above it goes away if you move to CollectionView.

@rmarinho
Copy link
Member

rmarinho commented May 5, 2022

@DavidCarKc about your 4th point, this is not a bug, you need to disable the button when it's tapped so it doesn't get clicked twice.

About your 1st point related with windows we are going to investigate but i think is better to open a new issue just for that so we don't get confuse.

Point n2 we have a fix for in a PR.

Thanks

@DavidCarKc
Copy link
Author

@rmarinho
Hi and thanks for looking into the problem, I was just trying different possibilities on how I could build apps trying the same thing with both ListView and CollectionView. CollectionView has it's own problems as my app starts with empty view which is being populated by user input and that does not work on android. Since I'm trying to have a multiplatform app I assumed same code would work the same way on all platforms. I would make a page in Windows and it would work great, test on Android does not work properly, change something, works on Android, now someting else does not work on windows etc.

2nd point I assumed the display would be refreshed after setting the list even if it is the same list, setting it to null first is not a big problem.

3rd point: add a button and a listview in xaml, for the OnButtonClicked event add 1 object to the list and DisplayAlert if you want to display the list in ListView. If the list has less than 15 object when displaying first time and then add one more object and confirm displaying it again it will crash the app. If the list has more than 15 objects when you display it for the first time and add an object or more and thed display the list in the ListView it won't crash the app but it will take like a minute to render it on display unless if you swipe up-down. The problem with CollectionView is on Android as it won't display anything on Android if it starts with 0 item on first display. You can use the code provided in the first post for testing.

4th You are saying that Every OnButtonClicked event that has an await DisplayAlert popup should be coded as following:
OnButtonClicked
{
Button.IsEnabled = false;
await DisplayAlert();
code;
Button.IsEnabled = true;
}
I assumed that the whole page would immediately be inaccessible to the user after calling the DisplayAlert.
This is not a problem for small apps but if someone wants to make an app based on many buttons the user could abuse this 100ms windows before the DisplayAlert Popup and start multiple processes when they sould not be started basicaly we would need following
OnButtonClicked
{
disableAllClickableThingsOnScreen();
await DisplayAlert();
code;
enableAllClickableThingsOnScreen();
}
Even more fun is if some of those clickable objects aren't enabled at start so then you would need like a list or a table with objects what should not be reenabled and should stay disabled in enableAllClickableThingsOnScreen();

Maybe I'm just trying to apply logic and ideas into my apps that isn't suitable for maui.
Anyway great job everyone trying to make maui work, I have high hopes for it, it will be a great tool once all bugs are polished.

@DavidCarKc
Copy link
Author

@rmarinho
Hi, just tested on
Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.2.0 Preview 6.0
Tried with ObservableCollections and I can confirm android problem with crashing while redisplaying low number of objects does not happen. Also in this version putting 15+ objects for first time display and then adding more aslo crashes if list is directly added as ListView.ItemsSource.
Now the interesting thing happens on windows,
1st - if(answer) - line was changed to:
if (answer) { ObservableCollection collection = new ObservableCollection(smallList); collectionView1.ItemsSource = collection; }
windows would still crash after 60 objects
2nd - decleared empty observable collection
ObservableCollection collection = new ObservableCollection()
and instead of adding objects to the list I added them to the OC
//smallList.Add(obj);
collection.Add(obj);
var answer = await DisplayAlert("CollectionView1", "Refresh CollectionView now?", "Yes", "No");
if (answer) {collectionView1.ItemsSource = collection; }// after first YES autorefreshes the display
NOW WINDOWS DISPLAYS MORE THAN 60 OBJECTS in ListView - tried 100+ and it didn't crash.
3rd - I tried to populate a list first, then one by one add objects to OC
//declared both empty
List smallList = new();
ObservableCollection collection = new ObservableCollection();
// added objects to the list
smallList.Add(obj);
//collection.Add(obj);
var answer = await DisplayAlert("CollectionView1", "Refresh CollectionView now?", "Yes", "No");
if (answer) {
while (collection.Count > 0) { collection.RemoveAt(0); }
foreach (SmallObject smallObject in smallList) {
collection.Add(smallObject);
}
collectionView1.ItemsSource = collection; }

And again it didn't crash on WINDOWS even with 100+ objects displayed. BUT on ANDROID it crashes on refresh.
ANDROID does not like when ListViewItemSource is set to null or if the collection on redisplay does not have any objects to display after it displayed some before, Windows does not mind that.
Also tried the same code with CollectionView and it worked on both platforms
I know there is ObservableCollection.ToList just wanted to test things.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
@samhouts samhouts added the fixed-in-6.0.312 Look for this fix in 6.0.312! label Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-listview ListView and TableView fixed-in-6.0.312 Look for this fix in 6.0.312! p/0 Work that we can't release without platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
8 participants