Exemplo n.º 1
0
  // 从网络中抓取数据,更新UI
  private void updateFromNet() {
    // 查询多条数据
    BmobQuery<Augur> query = new BmobQuery<Augur>();
    datas = new ArrayList<>();
    query.include("augur_pointer");
    // 判断是否有缓存,该方法必须放在查询条件(如果有的话)都设置完之后再来调用才有效,就像这里一样。
    boolean isCache = query.hasCachedResult(mycontext, Augur.class);
    if (isCache) {
      query.setCachePolicy(
          BmobQuery.CachePolicy.CACHE_ELSE_NETWORK); // 如果有缓存的话,则设置策略为CACHE_ELSE_NETWORK
    } else {
      query.setCachePolicy(
          BmobQuery.CachePolicy.NETWORK_ELSE_CACHE); // 如果没有缓存的话,则设置策略为NETWORK_ELSE_CACHE
    }
    query.findObjects(
        mycontext,
        new FindListener<Augur>() {
          @Override
          public void onSuccess(List<Augur> object) {
            // TODO Auto-generated method stub
            for (Augur augurbean : object) {
              datas.add(augurbean);
            }
            mAdapter.setMdatas(datas);
            mHandler.sendEmptyMessage(0);
            mSwipeLayout.setRefreshing(false);
          }

          @Override
          public void onError(int code, String msg) {
            // TODO Auto-generated method stub
            mHandler.sendEmptyMessage(0);
            if (mSwipeLayout != null) mSwipeLayout.setRefreshing(false);
          }
        });
  }
Exemplo n.º 2
0
  private void judgeAugur() {
    BmobQuery<MyUser> query = new BmobQuery<MyUser>();
    query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);
    query.getObject(
        mycontext,
        BmobUser.getCurrentUser(mycontext).getObjectId(),
        new GetListener<MyUser>() {

          @Override
          public void onSuccess(MyUser object) {
            // TODO Auto-generated method stub
            if (object.getType().equals("2")) {
              // 不能重复申请成为大师
              mycontext.toast("您已经是大师,不能重复申请");
              Log.e("datas", "MeFragment 判断type" + object.getType());
              btn_beaugur.setClickable(false);
            }
          }

          @Override
          public void onFailure(int code, String arg0) {}
        });
    initDatas();
  }