android框架之PullToRefresh下拉刷新
框架简介
android-PullToRefresh框架使用起来很简单,它支持下拉刷新也支持上拉加载。支持的控件包括:
ListView
ExpandableListView
GridView
WebView
ScrollView
HorizontalScrollView
ViewPager
代码实例:
先看效果图:
XML布局文件中:
<com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/pull_to_refresh_listview" android:layout_height="fill_parent" android:layout_width="fill_parent" />
Java文件中声明并使用
public class MainActivity extends Activity { PullToRefreshListView pullToRefreshView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview); String[] arr = {"1","2","3","4","5"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, arr); pullToRefreshView.setAdapter(adapter); pullToRefreshView .setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onRefresh( PullToRefreshBase<ListView> refreshView) { // Do work to refresh the list here. new GetDataTask().execute(); } }); } class GetDataTask extends AsyncTask<Void, Void, String[]> { @Override protected void onPostExecute(String[] result) { pullToRefreshView.onRefreshComplete();//结束刷新 super.onPostExecute(result); } @Override protected String[] doInBackground(Void... params) { try { Thread.sleep(2000);//控制刷新两秒 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } }
相关推荐
huavhuahua 2020-09-05
magic00 2020-08-03
风萧萧梦潇 2020-06-14
jiejie 2020-06-02
pengjin 2020-05-14
kururunga 2020-05-07
fengyeezju 2020-04-26
PrisonJoker 2020-04-16
fengyeezju 2020-04-07
hqulyc 2020-03-05
fengyeezju 2020-02-09
fengyeezju 2020-02-02
Urchindong 2020-01-21
fengyeezju 2020-01-11
绿豆饼 2020-01-05
csdnuuu 2019-12-27