我建立了一个像这样的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。我不明白为什么它会抛出这个。任何见解都将不胜感激。
答案 0 :(得分:0)
阅读另一个SO问题:
由于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
}