一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

android组件SwipeRefreshLayout下拉小球式刷新效果

时间:2017-04-16 编辑:简简单单 来源:一聚教程网

布局文件:

 

 代码如下 复制代码

xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity">

 

  

    android:id="@+id/swipeRefreshLayout"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

  >

   

     android:id="@+id/listView"

     android:layout_width="match_parent"

     android:layout_height="wrap_content">

   

  

 

 

MainActivity:

 

 代码如下 复制代码

publicclassMainActivityextendsAppCompatActivityimplementsSwipeRefreshLayout.OnRefreshListener{

 

privatestaticfinalintREFRESH_STATUS =0;

privateListView myListView;

privateSwipeRefreshLayout mySwipeRefreshLayout;

privateArrayAdapter listAdapter;

privateList listIDE =newArrayList(Arrays.asList("Visual Studio","Android Studio","Eclipse","Xcode"));

privateHandler refreshHandler =newHandler()

{

  publicvoidhandleMessage(android.os.Message msg)

  {

    switch(msg.what)

    {

      caseREFRESH_STATUS:

        listIDE.removeAll(listIDE);

        listIDE.addAll(Arrays.asList("C#","Java","C++","Object-C"));

        listAdapter.notifyDataSetChanged();

        mySwipeRefreshLayout.setRefreshing(false);

        break;

 

    }

  };

};

protectedvoidonCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  myListView = (ListView) findViewById(R.id.listView);

  mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);

 

  mySwipeRefreshLayout.setOnRefreshListener(this);

  mySwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,

      android.R.color.holo_orange_light, android.R.color.holo_red_light);

  listAdapter =newArrayAdapter(this,android.R.layout.simple_list_item_1,listIDE);

  myListView.setAdapter(listAdapter);

}

 

@Override

publicvoidonRefresh() {

  refreshHandler.sendEmptyMessageDelayed(REFRESH_STATUS,1500);

 }

}

 

效果图:

热门栏目