У меня есть основное действие, которое обрабатывает переключатели фрагментов в FrameLayout. Навигация для каждого из фрагментов контролируется BottomNavigationView.
Странно, что когда я перехожу к своему домашнему фрагменту, у которого есть RecyclerView, и прокручиваю вниз до конца, данные загружаются. , но если я начну снова, доберусь до своего домашнего фрагмента и переключусь на другой фрагмент, а затем вернусь к своему домашнему фрагменту и прокрутлю вниз, onScrollStateChanged никогда не будет вызван.
Я пробовал это в onCreateView, и происходит то же самое:
Некоторый код в моем onCreateView:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (rootView == null) {
rootView = inflater.inflate(R.layout.follow_fragment, container, false);
}
fInterest = new ArrayList();
//just change the fragment_dashboard
//with the fragment you want to inflate
//like if the class is HomeFragment it should have R.layout.home_fragment
//if it is DashboardFragment it should have R.layout.fragment_dashboard
main = (MainActivity) getContext();
main.iconRefresh.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Toast.makeText(((MainActivity) getContext()).getApplication(), "Follow News", Toast.LENGTH_SHORT);
}
});
main.iconSearch.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent(getActivity(), SearchActivity.class);
startActivity(intent);
}
});
childOverlay = new View(getActivity());
return rootView;
}
У меня есть это в onViewCreated:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
followInterestsList = (RecyclerView) rootView.findViewById(R.id.followInterestsList);
followInterestsList.setLayoutManager(new LinearLayoutManager(getContext()));
followInterestsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
//loadFollows(fInterest.get(fInterest.size() - 1).id);
} else {
// Scrolling down
String g = "";
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (!recyclerView.canScrollVertically(1)) {
//Toast.makeText(YourActivity.this, "Last", Toast.LENGTH_LONG).show();
if(!hasFinishedResults){
if(!isLoading){
//fInterest.removeIf(x -> x.isLoadMore == true);
loadFollows(fInterest.get(fInterest.size() - 1).id);
}
}else{
}
}
}
});
loadFollows(0);
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ing-called
Android – Recycler View onScrollStateChanged не вызывается ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение