gpt4 book ai didi

android - 键盘关闭时 Recyclerview 崩溃

转载 作者:太空狗 更新时间:2023-10-29 14:59:13 24 4
gpt4 key购买 nike

我像这样构建一个 recyclerview:

recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

currentResults = new ArrayList<Stuff>();
stuffAdapter = new StuffAdapter(currentResults, getActivity());
recyclerView.setAdapter(stuffAdapter);

然后当用户搜索事物并返回结果时,它们将以正常方式添加到适配器

currentResults.clear();
currentResults.addAll(searchResponse.results);
restaurantAdapter.notifyDataSetChanged();

这都是非常标准的。结果是通过 appcompat 工具栏中的 searchview 小部件和改造回调获得的。

问题是有一个特定的点,用户可以关闭键盘,UI 调整以适应,然后整个事情崩溃了

java.lang.UnsupportedOperationException: RecyclerView does not support scrolling to an absolute position. at  
android.support.v7.widget.RecyclerView.scrollTo(RecyclerView.java:941) at
android.view.View.setScrollX(View.java) at
android.animation.PropertyValuesHolder.nCallIntMethod(Native Method) at
android.animation.PropertyValuesHolder.access$200(PropertyValuesHolder.java)
at android.animation.PropertyValuesHolder$IntPropertyValuesHolder.setAnimatedValue(PropertyValuesH

没有人调用 scrollto。我不明白为什么要扔这个。任何见解将不胜感激。

最佳答案

阅读另一个 SO 问题:

java.lang.UnsupportedOperationException: RecyclerView does not support scrolling to an absolute position

问题仅出在某些特定设备上,因为那里实现了 ICS。作为建议的解决方法,您可以制作一个 CustomRecyclerView 来扩展 RecyclerView 并覆盖 scrollTo 以捕获错误并阻止应用程序崩溃。

@Override
public void scrollTo(int x, int y) {
Log.e(TAG, "CustomRecyclerView does not support scrolling to an absolute position.");
// Either don't call super here or call just for some phones, or try catch it. From default implementation we have removed the Runtime Exception trown
}

关于android - 键盘关闭时 Recyclerview 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28595458/

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