标签:android_studio pulltorefresh
本文以引入https://github.com/chrisbanes/Android-PullToRefresh为例
借鉴参考:http://www.apkbus.com/android-125663-1-1.html
本人电脑上的android studio是1.2.1.1 ,sdk api22.
依次导入android-pulltorefresh目录下的library、extras\PullToRefreshListFragment、extras\PullToRefreshListFragment
完成后目录如下
b.为demo下的app modules添加类库依赖。
完成后结果如上。点击“OK”完成。
3.解决编译错误
重新按"F12",修改除app外的其他三个modules中的min sdk和target sdk版本,与app相同
ok,编译可以正常通过了。
4、添加一个测试示例。
修改:layout/activity_main.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="demo.zhezi.MainActivity" android:orientation="vertical" > <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" > </com.handmark.pulltorefresh.library.PullToRefreshListView> </LinearLayout>
修改:MainActivity.java文件
private PullToRefreshListView listView ; private ArrayAdapter<String> arrayAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (PullToRefreshListView) findViewById(R.id.listview); arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); arrayAdapter.add("welcome"); arrayAdapter.add("welcome1"); arrayAdapter.add("welcome2"); arrayAdapter.add("welcome3"); listView.setAdapter(arrayAdapter); listView.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } return null; } protected void onPostExecute(Void result) { arrayAdapter.addAll("Hello","大家好"); listView.onRefreshComplete(); }; }.execute(); } });
好了。展示效果如下
本文出自 “peter的未来” 博客,请务必保留此出处http://peterxu.blog.51cto.com/1391852/1657631
标签:android_studio pulltorefresh
原文地址:http://peterxu.blog.51cto.com/1391852/1657631