2016-07-15 2 views
0

Когда вы выполняете код, время, нулевой указатель, я не могу понять, что делать дальше?Почему просмотр recycler не работает с загрузкой большей функциональности?

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout  
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="com.siliconinfo.loadmoredemo.MainActivity"> 

     <Button 
      android:id="@+id/openFragment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Click to open" /> 

      <FrameLayout android:id="@+id/contain" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/grey_dark" 
        xmlns:android="http://schemas.android.com/apk/res/android"> 

      </FrameLayout> 
    </LinearLayout> 

fragment_product.xml

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/filterSortLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white_dim_filter" 
      android:visibility="gone" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/filterProductLsit" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:drawableLeft="@mipmap/ic_filter_icon" 
       android:drawablePadding="@dimen/margin_10" 
       android:gravity="center_vertical" 
       android:padding="@dimen/margin_5" 
       android:text="@string/filter_text" 
       android:textColor="@color/grey_dark" 
       android:textSize="@dimen/drawer_subheader" /> 

      <TextView 
       android:id="@+id/sortProductList" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_marginLeft="@dimen/margin_5" 
       android:drawableLeft="@mipmap/ic_sort_icon" 
       android:drawablePadding="@dimen/margin_10" 
       android:gravity="center_vertical" 
       android:padding="@dimen/margin_5" 
       android:text="@string/sort_text" 
       android:textColor="@color/grey_dark" 
       android:textSize="@dimen/drawer_subheader" /> 

      <ImageView 
       android:id="@+id/gridListToggle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:padding="@dimen/activity_horizontal_margin" 
       android:src="@mipmap/gri_view_icon" /> 
     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:background="@color/skyblue_view" /> 

    <TextView 
     android:id="@+id/noDataMessageText" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:text="@string/no_item_found" 
     android:visibility="gone" /> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@mipmap/bestsellers_mainbg"> 

     <ProgressBar 
      android:id="@+id/progressBarItemsRecycler" 
      style="?android:progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" /> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/productListRecyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white_dim_details" 
      android:fitsSystemWindows="true" 
      android:visibility="gone" /> 

     <ProgressBar 
      android:id="@+id/progressBarItemsRecyclerOuter" 
      style="?android:progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:visibility="gone" /> 
    </FrameLayout> 
    </LinearLayout> 

макет набор строк в адаптер

row_gridviewtype.xml

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@mipmap/bestsellers_pro_listbg" 
      android:orientation="vertical" 
      android:padding="@dimen/margin_5"> 

       <FrameLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center"> 

       <ProgressBar 
       android:id="@+id/progressBarItems" 
       style="?android:progressBarStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" /> 

      <ImageView 
       android:id="@+id/imageview" 
       android:layout_width="@dimen/row_accessories_grid_width" 
       android:layout_height="@dimen/row_accessories_grid_width_hight" 
       android:src="@mipmap/no_image_available" 
       android:layout_gravity="center_horizontal" /> 
    </FrameLayout> 

    <TextView 
     android:id="@+id/productNameText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:singleLine="true" 
     android:textSize="@dimen/text_header" /> 

    <TextView 
     android:id="@+id/productPriceText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:paddingBottom="@dimen/margin_5" 
     android:paddingTop="@dimen/margin_5" 
     android:singleLine="true" 
     android:textColor="@color/skyblue_view" 
     android:textSize="@dimen/text_header" /> 

    <TextView 
     android:id="@+id/productRegularPriceText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:paddingBottom="@dimen/margin_5" 
     android:paddingTop="@dimen/margin_5" 
     android:singleLine="true" 
     android:textColor="@color/grey" 
     android:textSize="@dimen/text_header" /> 
    </LinearLayout> 

Это ProgressBar, загрузите ниже recyclerview, когда прокрутите просмотр ресайклера.

row_load.xml

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dp"> 
     <ProgressBar 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/progressBar" 
      android:layout_gravity="center_horizontal" /> 
     </LinearLayout> 

список DesktopFragment cointain

public class DeskPortTprtOurFvtAromaThrpyFragment extends Fragment implements View.OnClickListener { 
    private static String TAG ="DeskPortTprtOurFvtAromaThrpyFragment"; 
    private View mRoot; 
    private SharedPreferences mPreferences; 
    private Typeface mTypefaceBold,mTypefaceSemiBold,mTypefaceRegular; 
    private RecyclerView mProductListRecyclerView; 
    privateArrayList<ProductListResponseModel> 
    mProductListResponseModelArrayList = new ArrayList<ProductListResponseModel>(); 
    private ProgressBar mProgressBarRecycleView, mProgressBarOuter; 
    private boolean mVieType = true; 
    private String 
    mProductResponsePortableStr,mProductResponseDesktopStr, 
    mProductResponseTopRatedStr,mProductResponseOurFavouriteStr, 
    mProductResponseAromaTherapyStr, mCategoryStr; 
    String pageNumber = "", shortValue = "", storeId = "", shopByFrom= "", shopByTo = ""; 
    private TextView mFilterTextView, mSortTextView; 
    private ArrayList<String> categoryID = new ArrayList<String>(); 
    ArrayList<String> mCAtegoryIdFilter = new ArrayList<String>(); 
    private String shopByFrom1 = "", shopByFrom2 = "", shopByFrom3="", shopByTo1 = "", shopByTo2 = "", shopByTo3 = ""; 
    View.OnClickListener mFilterClickListener; 
    private String mFilterTag = "NO"; 
    private boolean zeroPosition = false, onePosition = false, secondPositon = false, thirdPosition = false; 
    String pageNo = "0"; 
    private ImageView mToggleViewListGridImageView; 
    Bundle productID; 
    ProductListAdaptr mProductListAdaptr; 
    private boolean loading = true; 
    int pastVisiblesItems, visibleItemCount, totalItemCount; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    mRoot = inflater.inflate(R.layout.fragment_product, container,false); 
    initView(); 
    return mRoot; 
    } 
    private void initView() { 
    mPreferences = getActivity().getSharedPreferences(Utils.PREF_NAME, Context.MODE_PRIVATE); 
    mToggleViewListGridImageView = (ImageView)mRoot.findViewById(R.id.gridListToggle); 
    ((ImageView)mRoot.findViewById(R.id.gridListToggle)).setOnClickListener(this); 

    mProductListRecyclerView = (RecyclerView) mRoot.findViewById(R.id.productListRecyclerView); 
    mFilterTextView = (TextView) mRoot.findViewById(R.id.filterProductLsit); 
    mSortTextView = (TextView) mRoot.findViewById(R.id.sortProductList); 
    ((TextView) mRoot.findViewById(R.id.filterProductLsit)).setOnClickListener(this); 
    ((TextView) mRoot.findViewById(R.id.sortProductList)).setOnClickListener(this); 

    Logger.e("TAG", "Product ID is : " + categoryID); 
    mProgressBarRecycleView = (ProgressBar) mRoot.findViewById(R.id.progressBarItemsRecycler); 
    mProgressBarOuter = (ProgressBar) mRoot.findViewById(R.id.progressBarItemsRecyclerOuter); 
    categoryID.add("10"); 
    mProductListAdaptr = new ProductListAdaptr(getContext(), mProductListResponseModelArrayList, mProductClickListener, 0); 

    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); 
    mProductListRecyclerView.setLayoutManager(linearLayoutManager); 
    mProductListRecyclerView.setItemAnimator(new DefaultItemAnimator()); 

    mProductListAdaptr.setLoadMoreListener(new ProductListAdaptr.OnLoadMoreListener() { 
     @Override 
     public void onLoadMore() { 
      mProductListRecyclerView.post(new Runnable() { 
       @Override 
       public void run() { 
        int index = mProductListResponseModelArrayList.size() - 1; 
        loadMore(index); 
       } 
      }); 
     } 
    }); 
    load(0); 
    } 

    private void load(int index) { 
    getProductList(categoryID, String.valueOf(index), "", "", "", "", "", "", "", "", ""); 
    } 

    private void loadMore(int index) { 

    } 


    private void showProductList() { 
    ((LinearLayout) mRoot.findViewById(R.id.filterSortLayout)).setVisibility(View.VISIBLE); 
    ((TextView) mRoot.findViewById(R.id.noDataMessageText)).setVisibility(View.GONE); 
    mProductListRecyclerView.setVisibility(View.VISIBLE); 
    if (mVieType == true) { 
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); 
    mProductListRecyclerView.setLayoutManager(linearLayoutManager); 
    ProductListRecyclerView.setItemAnimator(newDefaultItemAnimator()); 
    mProductListRecyclerView.setAdapter(new ProductListAdaptr(getContext(), mProductListResponseModelArrayList, mProductClickListener, 0)); 
    } else if (mVieType == false) { 
    final GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 2); 
    mProductListRecyclerView.setLayoutManager(mLayoutManager); 
    mProductListRecyclerView.setItemAnimator(new DefaultItemAnimator()); 
    mProductListRecyclerView.setAdapter(new ProductListAdaptr(getContext(), mProductListResponseModelArrayList, mProductClickListener, 1)); 
    } 
    mProductListResponseModelArrayList.addAll(mProductListResponseModelArrayList); 
    mProductListAdaptr.notifyDataChanged(); 
    } 

    private View.OnClickListener mProductClickListener = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     int position = (int) v.getTag(); 
    } 
    }; 

    private void getProductList(ArrayList<String> categoryId, String pagenumber, String shopByFrom1, String shopByTo1, 
          String shopByFrom2, String shopByTo2, String shopByFrom3, String shopByTo3, String shortValue, String storesID, String FilterTag) { 
    String categoryListString = ""; 
    for (int i = 0; i < categoryId.size(); i++) { 
     if (i == 0) 
      categoryListString = categoryId.get(i).toString(); 
     else 
      categoryListString = categoryListString + ", " + categoryId.get(i).toString(); 
    } 
    if (Utils.checkInternetConnection(getActivity())) { 
     final ProdcutListRequestTask mProductListRequestTask = new ProdcutListRequestTask(getActivity()); 
     mProductListRequestTask.setAsyncCallListener(new AsyncCallListener() { 
     @Override 
     public void onResponseReceived(Object response) { 
     mProductListResponseModelArrayList (ArrayList<ProductListResponseModel>) response; 
     ((LinearLayout)mRoot.findViewById(R.id.filterSortLayout)).setVisibility(View.VISIBLE); 
     mProgressBarOuter.setVisibility(View.GONE); 
     mProgressBarRecycleView.setVisibility(View.GONE); 
     if (mProductListResponseModelArrayList != null) { 
     Logger.e(TAG, "DektoPportaOurFavouriteFragment : " + mProductListResponseModelArrayList.size()); 
     } 
     if (response == null) return; 
       if (mProductListResponseModelArrayList == null || mProductListResponseModelArrayList.size() == 0) { 
        ((TextView) mRoot.findViewById(R.id.noDataMessageText)).setTypeface(mTypefaceBold); 
        ((TextView) mRoot.findViewById(R.id.noDataMessageText)).setVisibility(View.VISIBLE); 
        ((LinearLayout) mRoot.findViewById(R.id.filterSortLayout)).setVisibility(View.GONE); 
        return; 
       } 

       showProductList(); 
      } 

      @Override 
      public void onErrorReceived(String error) { 
       mProgressBarOuter.setVisibility(View.GONE); 
      } 
     }); 
     mProductListRequestTask.execute(categoryListString, pagenumber, shopByFrom1, shopByTo1, shopByFrom2, shopByTo2, shopByFrom3, shopByTo3, 
       shortValue, storesID, FilterTag); 
    } else { 
     Toast.makeText(getActivity(), getString(R.string.no_internet), Toast.LENGTH_SHORT).show(); 
     mProgressBarOuter.setVisibility(View.GONE); 
    } 
    } 
    } 
+0

1) «Я» всегда является столицей на английском языке. 2) Я попытался переформулировать ваш титул, но он все еще не очень ясен. Если вам нужны хорошие ответы, важно иметь легко поддающееся название, а не облако тегов. 3) Если вам нужна помощь для отладки, укажите минимально необходимый код, который воспроизводит проблему. – peterh

+0

Очень сложно предоставить помощь без [mcve] –

+0

@peterh моя проблема решена, но, получив одну проблему, у меня есть 2 кнопки, сетка и список, когда вы нажимаете на экран сетки отображения сетки и список отображения списка кликов, когда я меняю макет, что время загрузки больше не работает, другие мудрые работы очень хорошо, пришлите мне свой адрес электронной почты, я отправлю свой код, чтобы решить эту проблему, если возможно ,,, – Hitesh

ответ

0

использовать это, работает для меня.

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 
        @Override 
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
         super.onScrolled(recyclerView, dx, dy); 
         if (hasMore && !(hasFooter())) { 
          LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); 
          //position starts at 0 
          if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 2) { 
           new GetPostData().execute(); 
          } 
         } 
         else{ 

         } 
        } 
       }); 

надеюсь, что это также поможет вам.

+0

вы можете дать hasMore и hasFotter code, – Hitesh

+0

i do not no, как реализовать этот код – Hitesh

+0

посмотрите на этот пример, это поможет вам https://codentrick.com/load-more-recyclerview-bottom-progressbar/ – gaurang

Смежные вопросы