Answer the question
In order to leave comments, you need to log in
How to load the list first and then update it with SwipeRefreshLayout?
It is necessary that the list is loaded from the beginning, and then updated using SwipeRefreshLayout.
I get one thing.
Or the list is loaded but then it is not updated (although a reboot occurs).
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
ListView list_block = findViewById(R.id.list_block);
TextView contentView = findViewById(R.id.topText);
mSwipeRefreshLayout = findViewById(R.id.swipe_refresh);
...код загрузки списка...
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
ListView list_block = findViewById(R.id.list_block);
TextView contentView = findViewById(R.id.topText);
mSwipeRefreshLayout = findViewById(R.id.swipe_refresh);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
...код загрузки списка...
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
ListView list_block = findViewById(R.id.list_block);
TextView contentView = findViewById(R.id.topText);
mSwipeRefreshLayout = findViewById(R.id.swipe_refresh);
...код загрузки списка...
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
...код загрузки списка...
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
}
Answer the question
In order to leave comments, you need to log in
The second case is clearly wrong, because All the same, the list must first be loaded, and then it must be updated by swipe. Therefore, you don’t see anything, because. the formation of the list does not occur at the beginning, but after the setOnRefreshListener triggers on the mSwipeRefreshLayout element.
Why does list output not work in the first case? you hid the code (what a stupid habit?), and the telepaths all went to Bali to clear their chakras.
But if there is some kind of RecyclerViever, then it works something like this:
RecyclerView historyRecyclerView = binding.adrecyclerView;
historyRecyclerView = historyRecyclerView.findViewById(R.id.adrecycler_view);
HistoryViewRecycler historyView = new HistoryViewRecycler();
historyView.initRecycler(historyRecyclerView);
swipeRefreshLayout = binding.swipeRefreshLayout.findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//make new recycle view on swipe refresh
RecyclerView newhistoryRecyclerView = binding.adrecyclerView;
HistoryViewRecycler newhistoryView = new HistoryViewRecycler();
JSONArray newhistory = new HistoryViewRecycler().updateHistory(getContext());
if (newhistory == null) {
new History().getFullHistory(getContext());
//Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.auth_error, 3000).setDuration(5000).show();
}
newhistoryView.initRecycler(newhistoryRecyclerView);
swipeRefreshLayout.setRefreshing(false);
}
});
Move the data loading code into a separate method, and call it in two places (when creating an activity and inside the onRefresh method)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question