locked
How to use RefreshView in project type "Android App (Xamarin)" RRS feed

  • Question

  • User396309 posted

    Hi there,

    I have created a project of type "Android App (Xamarin)" in VS2019 which has the following activity_main.xml:

    ```

    android:id="@+id/web" android:layoutwidth="fillparent" android:layoutheight="fillparent"

    />
    

    ```

    I have code that uses the pipes a value from the built in NFC reader on Samsung tablet to the web page loaded into the WebView, and all is working well. However, if a page load stalls or the user gets an error in the web page for some reason, there is no way to refresh the page. I wanted to add a pull down to refresh, and also a pull from left to right to go back would be pretty cool as well, but will focus on pull to refresh in this post.

    I found a Xamarin Forms example of how to use the RefreshView to achieve this, but it doesn't seem to work in the Android only project.

    How can I use the RefreshView in my "Android App (Xamarin)" project, or is there a better way to do this?

    I am targeting Android 9.0.

    Thanks for your time.

    Wednesday, August 19, 2020 12:51 AM

Answers

  • User371688 posted

    Do you want to refresh the current page in xamarin android platform, right? Then you can use SwipeRefreshLayout to achieve this. The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. The activity that instantiates this view should add an OnRefreshListener to be notified whenever the swipe to refresh gesture is completed.

    You can use like this:

    ```

    refresher = FindViewById (Resource.Id.refresher); refresher.SetColorScheme (Resource.Color.xamdarkblue, Resource.Color.xampurple, Resource.Color.xamgray, Resource.Color.xam_green); refresher.Refresh += async delegate { // other code refresher.Refreshing = false; }; ```

    Here is an official sample about this, you can check it there: https://docs.microsoft.com/en-us/samples/xamarin/monodroid-samples/swipetorefresh/

    And you can also check the following link, it should be helpful for you. https://forums.xamarin.com/discussion/87412/swipe-to-refresh-in-code https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout https://www.nuget.org/packages/Xamarin.Android.Support.SwipeRefreshLayout/

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, August 19, 2020 3:16 AM

All replies

  • User371688 posted

    Do you want to refresh the current page in xamarin android platform, right? Then you can use SwipeRefreshLayout to achieve this. The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. The activity that instantiates this view should add an OnRefreshListener to be notified whenever the swipe to refresh gesture is completed.

    You can use like this:

    ```

    refresher = FindViewById (Resource.Id.refresher); refresher.SetColorScheme (Resource.Color.xamdarkblue, Resource.Color.xampurple, Resource.Color.xamgray, Resource.Color.xam_green); refresher.Refresh += async delegate { // other code refresher.Refreshing = false; }; ```

    Here is an official sample about this, you can check it there: https://docs.microsoft.com/en-us/samples/xamarin/monodroid-samples/swipetorefresh/

    And you can also check the following link, it should be helpful for you. https://forums.xamarin.com/discussion/87412/swipe-to-refresh-in-code https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout https://www.nuget.org/packages/Xamarin.Android.Support.SwipeRefreshLayout/

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, August 19, 2020 3:16 AM
  • User396309 posted

    @jezh Thanks this is what I was after. Much appreicated.

    Wednesday, August 19, 2020 5:05 AM
  • User371688 posted

    Hi @slaughton , if my reply is useful for you , could you please mark it as answerd so that it will help others who have similar questions? Thanks in advance. :)

    Wednesday, August 19, 2020 5:15 AM
  • User396309 posted

    @jezh, yep this was my first post I was looking for an option to do that at the top where it said Flag, Quote, Like as this is where all the actions seem to be grouped... but didn't see it. Now see it is at the bottom ;-)

    Wednesday, August 19, 2020 5:18 AM
  • User371688 posted

    Thank you very much for your support for xamarin. Have a nice day. :)

    Wednesday, August 19, 2020 5:20 AM