gpt4 book ai didi

android - 加载更多在 RecyclerView 中无法正常工作

转载 作者:行者123 更新时间:2023-11-29 02:34:41 24 4
gpt4 key购买 nike

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

      @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 中添加新项目才能保存以前的项目样式?谢谢

最佳答案

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

关于android - 加载更多在 RecyclerView 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47760513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com