コード例 #1
0
  private void setupRecyclerView() {
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setHasFixedSize(true);

    String tag = getArguments().getString(K.KEY_TAG.name());
    Cursor cursor =
        mActivity
            .getContentResolver()
            .query(
                SchemaPosts.CONTENT_URI,
                null,
                SchemaPosts.COLUMN_SRC_SEARCH + "=?",
                new String[] {tag},
                BaseColumns._ID + " DESC");
    if (cursor.moveToFirst()) {
      mViewAdapter = new PostCursorRecyclerViewAdapter(mActivity, cursor);
    } else {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      mViewAdapter = new PostCursorRecyclerViewAdapter(mActivity, null);
    }

    mViewAdapter.setHasStableIds(Boolean.TRUE);
    mRecyclerView.setAdapter(mViewAdapter);

    // scroll listerer on recycle view
    mRecyclerViewScrollListener =
        new EndlessRecyclerOnScrollListener(
            mLayoutManager, AppConstants.KV.LOAD_MORE.getIntValue()) {
          @Override
          public void onLoadMore(RecyclerView rv, int current_page) {
            mHandler.post(
                new Runnable() {
                  @Override
                  public void run() {
                    callForRemotePosts(Boolean.TRUE);
                  }
                });
          }
        };
    reInitializeScrollListener(mRecyclerView);

    // STYLE :: DIVIDER
    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(mActivity));
  }
コード例 #2
0
 private void reInitializeScrollListener(RecyclerView rv) {
   try {
     // buggy code
     rv.removeOnScrollListener(mRecyclerViewScrollListener);
     mRecyclerViewScrollListener =
         new EndlessRecyclerOnScrollListener(
             mLayoutManager, AppConstants.KV.LOAD_MORE.getIntValue()) {
           @Override
           public void onLoadMore(RecyclerView rv, int current_page) {
             mHandler.post(
                 new Runnable() {
                   @Override
                   public void run() {
                     callForRemotePosts(Boolean.TRUE);
                   }
                 });
           }
         };
     rv.addOnScrollListener(mRecyclerViewScrollListener);
   } catch (Exception e) {
     // muted
     //            e.printStackTrace();
   }
 }