Recyclerview update question if button is pressed again.

Asked 1 years ago, Updated 1 years ago, 87 views

When you click button, asyncask.execute() shows the parsing of json from url in recyclerview. There are a total of 5 buttons and one recyclerview for each button. There is no problem with just pressing the button once and scrolling and continuing to show, but if you scroll and press another button, it does not scroll and only shows the data that you show at first. I think there is a problem with updating the adapter, so please help me <

    ladderbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RankingRecyclerViewItemList.clear();
            adapter.notifyDataSetChanged();
            KdaRankingrv.setVisibility(View.GONE);
            rankingrv.setVisibility(View.VISIBLE);
            new ladderAsyncTask().execute(url1);
        }
    });

    killDeathbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RankingRecyclerViewItemList.clear();
            adapter.notifyDataSetChanged();
            rankingrv.setVisibility(View.GONE);
            KdaRankingrv.setVisibility(View.VISIBLE);
            new kdaAsyncTask().execute(url2);
        }
    });

This is when you click the button.

            adapter.notifyDataSetChanged();
            rankingrv.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);

                    visibleItemCount = rankingrv.getChildCount();
                    totalItemCount = linearLayoutManager.getItemCount();
                    firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();

                    if (loading) {
                        if (totalItemCount > previousTotal) {
                            loading = false;
                            previousTotal = totalItemCount;
                        }
                    }
                    if (!loading && (totalItemCount - visibleItemCount)
                            <= (firstVisibleItem + visibleThreshold)) {
                        // // End has been reached

                        Log.i("Yaeye!", "end called");

                        new ladderAsyncTask2().execute(url1);
                        // // Do something

                        loading = true;
                    }

                }
            });

This is an implementation of when the scroll went down in postexecute in asynctask.

recyclerview json button

2022-09-22 08:04

1 Answers

I'm thinking about the same problem. If you solve it first, please write it~^

^


2022-09-22 08:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.