2

我有自定义recyclerView。在项目中长按我会隐藏一些视图并显示另一个视图(隐藏图像视图并显示复选框)这是我的代码片段

      @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);
                }
            }

        }

一切正常,但我还有另一个问题。我会尝试解释我的问题在我的 recyclerView 中,我正在使用加载更多规范。当加载更多操作实现时,我的所有复选框都已隐藏,recyclerView 的样式都已隐藏。(我所有的复选框都隐藏了).这是我的加载更多功能

 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();
            }

        }

我认为问题是 notifyDataSetChanged。如何在 recyclerView 中添加新项目可以保存以前的项目样式?谢谢

4

1 回答 1

0

您应该在数据中维护一些标志,基于此您可以切换视图的可见性。

于 2017-12-12T05:12:08.327 回答