亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

拉動刷新(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 關注
  • 205 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號