2

I have custom recyclerView.In items long click I would to hide some views and show another view(hide imageviews and show Checkboxs) Here is a my code's snippet

      @Override
        public void onLongClickListener(String type, final int pos) {
            if (serverStatus == 4) {
                for (int i = 0; i < recyclerView.getChildCount(); i++) {
                    View view = recyclerView.getChildAt(i);
                    if (view == null) {
                        return;
                    }
                    final CircleImageView circleImageView = view.findViewById(R.id.circle_image);
                    final LetterImageView letterImageView = view.findViewById(R.id.iv_avatar);
                    final AppCompatCheckBox appCompatCheckBox = view.findViewById(R.id.checkbox);

                    letterImageView.setVisibility(View.GONE);
                    circleImageView.setVisibility(View.GONE);
                    final int finalI = i;

                    if (i == pos) {
                        appCompatCheckBox.setChecked(true);
                        currenctAmount = currenctAmount + Double.parseDouble(recyclerAdapter.getItem(finalI).getPrice());
                        ((DashboardActivity) getActivity()).showFourTabHeader(currenctAmount + "");

                        ((DashboardActivity) getActivity()).hideBottomBar();

                    }

                    appCompatCheckBox.setVisibility(View.VISIBLE);
                }
            }

        }

Everything working perfect but I have another problem.I'll try to explain my problem In my recyclerView I'm using load more specification.When load more action implemented all my checkbox has hidden and recyclerView's has previous style.(all my checkbox are hidden).Here is a my load more function

 if (recyclerAdapter != null) {
        recyclerAdapter.setmOnLoadMoreListener(new RecyclerAdapter.OnLoadMoreListener() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onLoadMore() {
                packagesLists.add(null);
                recyclerAdapter.notifyItemInserted(packagesLists.size() - 1);

                getpackageRequest(false, serverStatus,
                        recyclerAdapter.getItemCount(),
                        null,
                        payStatus, true);
            }
        });
    }



public void getpackageRequest(boolean allowShowDialog, final int serverStatus, int start, String searchParameters, final int payStatus, final boolean loadMore) {



    DataRepository dataRepository = new DataRepository(getActivity());

    dataRepository.getVolleyRequest(allowShowDialog, Request.Method.GET, url, new HashMap<String, String>(), new DataRepository.DaTaRepositoryCallback() {
        @Override
        public void onSuccess(String response) throws JSONException {
            JSONObject jsonObject = new JSONObject(response);



            Log.e("response packages", jsonObject.toString() + "mm");
            int errorcode = jsonObject.getInt("errorcode");
            String message = jsonObject.getString("message");

            if (errorcode == 0) {

                JSONObject dataObject = jsonObject.getJSONObject("data");
                packageSize = dataObject.getInt("count");
                ((DashboardActivity) getActivity()).updateHeaderValue(packageSize);

                JSONArray listArray = dataObject.getJSONArray("list");


                if (listArray.length() > 0) {
                    emptyLayout.setVisibility(View.GONE);
                    recyclerView.setVisibility(View.VISIBLE);

                    if (loadMore) {
                        packagesLists.remove(packagesLists.size() - 1);
                        recyclerAdapter.notifyItemRemoved(packagesLists.size());
                        recyclerAdapter.setLoaded();

                    }


                    Gson gson = new Gson();
                    PackagesList[] packages = gson.fromJson(listArray.toString(), PackagesList[].class);
                    packagesLists.addAll(Arrays.asList(packages));
                    recyclerAdapter.notifyDataSetChanged();


                } else {

                    if (!loadMore) {
                        recyclerView.setVisibility(View.GONE);
                        emptyLayout.setVisibility(View.VISIBLE);
                    }


                }
            } else {
                new MaterialDialog.Builder(getActivity())
                        .content(message)
                        .positiveText(getString(R.string.u_yes))
                        .show();
            }

        }

I think problem is notifyDataSetChanged.How I can add new items in recyclerView can save previous items styles? Thanks

BekaKK
  • 2,173
  • 6
  • 42
  • 80

1 Answers1

0

You should maintain some flag in data, based on that you can toggle visibility of your views.