上拉下拉分页加载

第三方登录获取授权

Platform platform11 = ShareSDK.getPlatform(QQ.NAME);
// platform11.SSOSetting(true);
platform11.authorize();
platform11.showUser(null);// 必须要加的要不然不行!这个才是授权的!
tm = (TelephonyManager) MainActivity.this
                .getSystemService(TELEPHONY_SERVICE);
imi = tm.getDeviceId();
platform11.setPlatformActionListener(new PlatformActionListener() {
@Override
public void onError(Platform platform11, int arg1,
        Throwable arg2) {
        // 弹出失败窗口
}

public void onComplete(Platform platform11, int arg1,
                    HashMap<String, Object> arg2) {
    System.out.println("登录成功。。。。");
    //得到用户信息
    String userId = platform11.getDb().getUserId();
    String userName = platform11.getDb().getUserName();
    String token = platform11.getDb().getToken();
    String icon = platform11.getDb().getUserIcon();//用户头像
    long expiresTime = platform11.getDb().getExpiresTime();
    SimpleDateFormat sdf3 = new SimpleDateFormat(
                        "yyyy-MM-dd HH:mm");


    System.out.println("userId    " + userId);
    System.out.println("userName    " + userName);
    System.out.println("token     " + token);
    System.out.println("icon     " + icon);
    System.out.println("expiresTime  "
                        + sdf3.format(expiresTime));

    //跳转页面传值
    Intent intent = new Intent(getApplicationContext(), ShowActivity.class);
                //传用户名和头像
    intent.putExtra("name", userName);
    intent.putExtra("image", icon);
    startActivity(intent);
        }
            @Override
    public void onCancel(Platform arg0, int arg1) {
            }
        });

请求网络数据上拉刷新下拉加载进行分页操作

private void getinfo(final String str) {
    new AsyncTask<Void, Void, List<nList>>() {

        @Override
        protected List<nList> doInBackground(Void... params) {

            //i代表页数
            String path = "http://api.sina.cn/sinago/list.json?channel=hdpic_funny&adid=4ad30dabe134695c3b7c3a65977d7e72&wm=b207&from=6042095012&chwm=12050_0001&oldchwm=12050_0001&imei=867064013906290&uid=802909da86d9f5fc&p="
                    + i;
            // 得到请求的数据
            String string = MyHttp.getHttp(path);
            Gson gson = new Gson();
            Type type = new TypeToken<News>() {
            }.getType();
            News news = gson.fromJson(string, type);
            Data data = news.data;
            List<nList> list = data.list;
            return list;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(List<nList> result) {
            super.onPostExecute(result);
            //调用方法的时候判断是上拉还是下拉,上拉加载新的数据到集合顶部,下拉加载新的数据到集合中
            if (str.equals("刷新")) {
                listall.addAll(0, result);
            } else {
                listall.addAll(result);
            }
            //添加适配器
            setadapter();
        }

        private void setadapter() {
        //在添加适配器时候,判断是否创建了适配器,如果适配器创建,直接适配器更新,否则创建适配器
            if (adapter == null) {
                adapter = new Myadapter(ShowActivity.this, listall);
                listView.setAdapter(adapter);
            } else {
                adapter.notifyDataSetChanged();
            }
        }
    }.execute();
}
上拉刷新方法
@Override
public void onRefresh() {
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            i = i + 1;
            getinfo("刷新");
            load();
        }
    }, 2000);
}
下拉加载的方法
@Override
public void onLoadMore() {
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            i = i + 1;
            getinfo("加载");
            load();
        }
    }, 2000);
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值