下拉刷新 下拉加载

http://www.it165.net/pro/html/201410/24954.html
activity——xml
##导入library时不能导入的问题
library文件下缺少这两个文件在别的文件下拷贝。
这里写图片描述
#####关于PullToRefreshListView 和 getItemAtPosition
http://www.itstrike.cn/Question/736d7601-49bc-42e1-87a1-6cb664876e31.html
####区分上拉和下拉
http://www.tuicool.com/articles/ZfmiEj

  refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
		                if (refreshView.isShownHeader()) {
		                	if (mList!=null) {
			                	 mList.clear();
							}
		                	   getAllInformation(false, 0);
		                	   new GetDataTask().execute();
						}
		                if (refreshView.isShownFooter()) {
		                	   getAllInformation(false, 2);
		                	   new GetDataTask().execute(); 
						}
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long id) {
		// TODO Auto-generated method stub
		RuKuJcVo bean = (RuKuJcVo) arg0.getItemAtPosition(position);
		Intent mintent = new Intent(getActivity(), RuKuDetailActivity.class);
		mintent.putExtra("mainId", bean.getID());// id
		mintent.putExtra("BusX", bean.getPym());// 车型
		mintent.putExtra("BusH", bean.getLocono());// 车号
		System.out.println("当前机车ID===" + bean.getID());
		startActivity(mintent);
	}
<!--  xmlns:ptr = "http://schemas.android.com/apk/res-auto"  为我们要使用PullToRefresh 里面一些属性需要引的命名空间 -->
      <com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:ptr = "http://schemas.android.com/apk/res-auto" 
        android:id="@+id/pull_refresh_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="4dp"
        android:fadingEdge="none"
        android:fastScrollEnabled="false"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:smoothScrollbar="true"
		ptr:ptrMode="both"
         />


Activity

public class MainActivity extends Activity {
	private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",  
			            "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",  
			            "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",  
			            "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",  
			            "Allgauer Emmentaler" };  
	private LinkedList<String> mListItems;  
    private PullToRefreshListView mPullRefreshListView;  
    private ArrayAdapter<String> mAdapter;  


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);  
        mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {  
        	            @Override  
        	            public void onRefresh(PullToRefreshBase<ListView> refreshView) {  
        	               String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),  
                               DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);  
        	 
        	                // Update the LastUpdatedLabel  
        	               refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);  
        	  
        	                // Do work to refresh the list here.  
                        new GetDataTask().execute();  
        	            }  
        	        });  
        mListItems = new LinkedList<String>();  
             mListItems.addAll(Arrays.asList(mStrings));  
    
              mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);  
        
              //这两个绑定方法用其一  
              // 方法一  
      //       mPullRefreshListView.setAdapter(mAdapter);  
               //方法二  
               ListView actualListView = mPullRefreshListView.getRefreshableView();  
             actualListView.setAdapter(mAdapter);  
          }  
         
           private class GetDataTask extends AsyncTask<Void, Void, String> {  
         
               //后台处理部分  
        @Override  
               protected String doInBackground(Void... params) {  
                   // Simulates a background job.  
                  try {  
                       Thread.sleep(1000);  
                   } catch (InterruptedException e) {  
                  }  
                   String str="Added after refresh...I add";  
                   return str;  
               }  
          
                //这里是对刷新的响应,可以利用addFirst()和addLast()函数将新加的内容加到LISTView中  
              //根据AsyncTask的原理,onPostExecute里的result的值就是doInBackground()的返回值  
                @Override  
               protected void onPostExecute(String result) {  
                   //在头部增加新添内容  
                    mListItems.addFirst(result);  
                      
                  //通知程序数据集已经改变,如果不做通知,那么将不会刷新mListItems的集合  
                    mAdapter.notifyDataSetChanged();  
                   // Call onRefreshComplete when the list has been refreshed.  
                    mPullRefreshListView.onRefreshComplete();  
          
                   super.onPostExecute(result);  
               }  
              
        
  


    }
    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值