Example #1
0
  public MVCHelper(IRefreshView refreshView, ILoadView loadView, ILoadMoreView loadMoreView) {
    super();
    this.context = refreshView.getContentView().getContext().getApplicationContext();
    this.autoLoadMore = true;
    this.refreshView = refreshView;
    contentView = refreshView.getContentView();
    contentView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    refreshView.setOnRefreshListener(onRefreshListener);
    if (loadMoreView != null) {
      if (contentView instanceof ListView) {
        final ListView listView = (ListView) contentView;
        listView.setCacheColorHint(Color.TRANSPARENT);
        listView.setOnScrollListener(new ListViewOnScrollListener());
        listView.setOnItemSelectedListener(new ListViewOnItemSelectedListener());
        mLoadMoreView = loadMoreView;
        mLoadMoreView.init(
            new FootViewAdder() {

              @Override
              public View addFootView(int layoutId) {
                View view = LayoutInflater.from(context).inflate(layoutId, listView, false);
                return addFootView(view);
              }

              @Override
              public View addFootView(View view) {
                listView.addFooterView(view);
                return view;
              }
            },
            onClickLoadMoreListener);
      } else if (contentView instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) contentView;
        recyclerView.setOnScrollListener(new RecyclerViewOnScrollListener());
        mLoadMoreView = loadMoreView;
      }
    }
    mLoadView = loadView;
    mLoadView.init(refreshView.getSwitchView(), onClickRefresListener);
  }
Example #2
0
  /**
   * 设置适配器,用于显示数据
   *
   * @param adapter
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public void setAdapter(IDataAdapter<DATA> adapter) {
    if (contentView instanceof AbsListView) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ((AbsListView) contentView).setAdapter((ListAdapter) adapter);
      } else {
        try {
          Method method = contentView.getClass().getDeclaredMethod("setAdapter", ListAdapter.class);
          method.invoke(contentView, adapter);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } else if (contentView instanceof RecyclerView) {
      RecyclerView.Adapter<?> adapter2 = (Adapter<?>) adapter;
      final RecyclerView recyclerView = (RecyclerView) contentView;
      if (mLoadMoreView != null) {
        final HFRecyclerAdapter hfAdapter = new HFRecyclerAdapter(adapter2);
        adapter2 = hfAdapter;
        mLoadMoreView.init(
            new FootViewAdder() {

              @Override
              public View addFootView(int layoutId) {
                View view = LayoutInflater.from(context).inflate(layoutId, recyclerView, false);
                return addFootView(view);
              }

              @Override
              public View addFootView(View view) {
                hfAdapter.addFooter(view);
                return view;
              }
            },
            onClickLoadMoreListener);
      }
      recyclerView.setAdapter(adapter2);
    }
    this.dataAdapter = adapter;
  }
Example #3
0
 public void setAutoLoadMore(boolean autoLoadMore) {
   this.autoLoadMore = autoLoadMore;
   if (!isLoading()) {
     mLoadMoreView.showNormal();
   }
 }