为了账号安全,请及时绑定邮箱和手机立即绑定

拉动刷新(SwipeRefreshLayout)android xamarin c#

拉动刷新(SwipeRefreshLayout)android xamarin c#

C#
一只名叫tom的猫 2022-01-15 17:30:25
我需要在主页屏幕中添加拉动刷新。一开始,axml 是:初始代码  [1]:https://pastebin.com/iZNFiqgt我添加了 swipeRefreshLayout 所以:代码滑动刷新在课堂上,我添加了以下代码:............SwipeRefreshLayout refreshLayoutprotected override void OnCreate (Bundle savedInstanceState){.........refreshLayout = FindViewById<SwipeRefreshLayout> . (Resource.Id.swipeRefreshLayout1);refreshLayout.Refresh += RefreshLayout_Refresh}void RefreshLayout_Refresh(object sender, EventArgs e){ //insert action pull to refresh Console.WriteLine("start pull to refresh"); //after delete it and insert the action }但是当我尝试 pullRefresh 页面时应用程序崩溃。错误是:
查看完整描述

1 回答

?
当年话下

TA贡献1890条经验 获得超9个赞

只要用户可以通过垂直滑动手势刷新视图的SwipeRefreshLayout内容,就应该使用 。阅读更多


所以,SwipeRefreshLayout它的行为就像一个容器,所以SwipeRefreshLayout你应该在里面添加一个ListVieworGridView来让它工作,如下所示:


请记住,SwipeRefreshLayout只支持一个ListView或一个GridView孩子。


<LinearLayout

  xmlns:android="http://schemas.android.com/apk/res/android"

  xmlns:app="http://schemas.android.com/apk/res-auto"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical">


  <android.support.v4.widget.SwipeRefreshLayout

     android:id="@+id/swipeRefreshLayout"

     android:layout_width="match_parent"

     android:layout_height="match_parent">


       <ListView 

         android:id="@+id/list"

         android:layout_width="match_parent"

         android:layout_height="match_parent"/>


  </android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

然后,设置您的视图元素:


SwipeRefreshLayout swipeRefreshLayout;

ListView listView;    


protected override void OnCreate(Bundle savedInstanceState)

{

   // ...


   listView = view.FindViewById<ListView>(Resource.Id.list);

   swipeRefreshLayout = view.FindViewById<SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);


   // Elevation helps users understand the relative importance of each element and focus their attention to the task at hand. (Optional)

   // swipeRefreshLayout.Elevation = 10; 


   swipeRefreshLayout.Refresh += delegate (object sender, System.EventArgs e)

   {

      // logic...

   };


   // ...

}

此外,您可以通过以下方式手动触发SwipeRefreshLayout:


swipeRefreshLayout.Post(() => { 

   swipeRefreshLayout.Refreshing = true; 

   listView.Clickable = false; 

});


// logic...


swipeRefreshLayout.Post(() => { 

   swipeRefreshLayout.Refreshing = false; 

   listView.Clickable = true; 

});

我希望这可以帮助你。


查看完整回答
反对 回复 2022-01-15
  • 1 回答
  • 0 关注
  • 190 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信