Refreshing current activity

Hello guys ! I am new to Xamarin and I am trying to refresh my MainActivity from itself. I read a lot of forums about that but I still can't find any solution. My problem is that I need to do the refreshing from another method, not within the onCreate() method.

Thanks in advance ! :)


  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭

    Can you tell us more about what you are trying to do? Why do you need to refresh your activity? Can OnResume() be helpful?

  • StefanStefanovStefanStefanov USMember
    edited September 2014

    My MainActivity is a listview and I want to reload the whole activity in order to refresh the listview. I need to reload the whole activity cuz in my situation I can't use NotifyDataSetChanged() because the changes I am making to the listview are not within the onCreate() method and not in a new activity neither. I have a CAB menu from where the user has the option to delete selected note from the listview. I am using the NotifyDataSetChanged() method in my onResume() method and it's working perfectly when I am making the changes to my listview in another activity but it's not working when I am making them from the current activity cuz then the onResume() method is not being called .

  • StefanStefanovStefanStefanov USMember
    edited September 2014

    I am trying doing it like this :

    Intent refresh = new Intent(this ,typeof(MainActivity));

    but it's giving me NullPointerException on the first row already .. And the exception I think is the "this". So I tried it differently : instead of using "this" I am using - Intent refresh = new Intent(context ,typeof(MainActivity)); where context=this in the onCreate() method. But in this way it's still giving me a NullPointerException but this time on the row - StartActivity(refresh) ..

  • ShailDShailD USMember ✭✭
    edited September 2014

    Wouldn't a simple call to this.Recreate() suffice?

    We use this to "refresh" the Activity every time user switches the app's language using a toggle-button.

    See this page of Android documentation.

  • I've already tried using this.Recreate() but it's giving me NullPointerException ..

  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭

    A quick way to refresh a listview is by updating its adapter. One way, probably not the best, is to attach a new instance. This would look like ListView.Adapter = new MyListViewAdapter();. Another way would be to provide a method inside your adapter that can be called outside like myListViewAdapter.Update();

    But to be able to help you and stop guessing it would be helpful if you can post your activity implementation.

  • guruvusettyguruvusetty USMember
    edited September 2015

    Can any one explain with an example on Refreshing current activity on button click event.

  • HirHir USMember ✭✭

    hello , for refreshing the layout page simply.....rebind the page with layout....

    do this at activity when you wann to refresh the add new item on listview

Sign In or Register to comment.