DEV Community

Sem
Sem

Posted on • Originally published at semihcelikol.com

2 1

Xamarin.Android - Using SwipeRefreshLayout

Layout:

    <android.support.v4.widget.SwipeRefreshLayout
                    android:id="@+id/swipeRefreshLayoutMain"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ListView
                        android:id="@+id/listMain"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"/>

                </android.support.v4.widget.SwipeRefreshLayout>
Enter fullscreen mode Exit fullscreen mode

Activity:


    using Android.App;
    using Android.OS;
    using Android.Support.V7.App;
    using Android.Runtime;
    using Android.Widget;
    using Android.Support.V4.Widget;

    namespace SwipeRefreshExample
    {
        [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
        public class MainActivity : AppCompatActivity
        {
            ListView listMain;
            SwipeRefreshLayout swipeRefreshLayoutMain;

            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.activity_main);

                listMain = FindViewById<ListView>(Resource.Id.listMain);
                swipeRefreshLayoutMain = FindViewById<SwipeRefreshLayout>(Resource.Id.swipeRefreshLayoutMain);

                swipeRefreshLayoutMain.Refresh += SwipeRefreshLayoutMain_Refresh;
            }

            private void SwipeRefreshLayoutMain_Refresh(object sender, System.EventArgs e)
            {
                showData();
                swipeRefreshLayoutMain.Refreshing = false;
            }

            public void showData()
            {
                string[] data = new string[] { "Data 1", "Data 2", "Data 3", "Data 4", "Data 5" };

                ArrayAdapter arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, data);

                listMain.Adapter = arrayAdapter;
            }

            public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
            {
                Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

                base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }
    }
Enter fullscreen mode Exit fullscreen mode

Finish and Output:

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more