0
下午好,android.support.v4.widget.NestedScrollView不能轉換爲android.support.v7.widget.RecyclerView
我試圖創建一個包括項RecyclerView片段。
以上這些項目,我需要把一些標題與一些過濾器。
這裏是片段的XML (fragment_products_list):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12sp"
android:id="@+id/filters_frame">
<include layout="@layout/expandable_filters"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
這裏是OnCreateView在我的片段Java文件(ListFragment.java):
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RecyclerView rv = (RecyclerView) inflater.inflate(
R.layout.fragment_products_list, container, false);
//Product filters
expandFiltersButton = (ImageButton) getView().findViewById(R.id.expand_filters);
expandableZone = (LinearLayout) getView().findViewById(R.id.expandable_zone);
expandFiltersButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(expandableZone.isShown()){
expandableZone.setVisibility(View.GONE);
expandFiltersButton.setImageResource(R.drawable.ic_more_24dp);
}else{
expandableZone.setVisibility(View.VISIBLE);
expandFiltersButton.setImageResource(R.drawable.ic_less_24dp);
}
}
});
setupRecyclerView(rv);
mRecyclerView = rv;
loadUpdates();
return rv;
}
我有這樣的錯誤代碼當我試圖運行該應用程序:
android.support.v4.widget.NestedScrollView cannot be cast to android.support.v7.widget.RecyclerView
什麼問題,我該如何解決? 感謝您的幫助!
你找到最終的解決方案,非常感謝你! –
很高興幫助! –