Возможно, вы увидите пару одинаковых вопросов, но это не помогло мне решить эту проблему.java.lang.ClassCastException: android.support.v7.widget.RecyclerView не может быть отброшен в android.support.v4.widget.SwipeRefreshLayout
Мой XML содержит RecyclerView
внутри SwipeRefreshLayout
. Когда я запускаю свой код, он вызывается ниже исключения или сбоя приложения.
java.lang.RuntimeException: Невозможно начать деятельность ComponentInfo {}: java.lang.ClassCastException: android.support.v7.widget.RecyclerView не может быть приведен к android.support.v4.widget.SwipeRefreshLayout
Мой XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rlSearch"
android:layout_above="@+id/rlBottomCreateIncident"
android:layout_margin="5dp">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout_Incidents"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_Incidents"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Java код внутри активность:
private void initializeUI() {
//Initialize swipe to refresh view
mSwipeRefreshLayoutIncidents = (SwipeRefreshLayout) findViewById(R.id.recyclerView_Incidents);
mSwipeRefreshLayoutIncidents.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
mSwipeRefreshLayoutIncidents.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//Refreshing data on server
}
});
mSwipeRefreshLayoutIncidents.setRefreshing(true);
recyclerViewIncidents = (RecyclerView) findViewById(R.id.recyclerView_Incidents);
sp_incidentAdapter = new SP_IncidentAdapter(context, sp_incidentListItemArrayList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerViewIncidents.setLayoutManager(mLayoutManager);
recyclerViewIncidents.setItemAnimator(new DefaultItemAnimator());
recyclerViewIncidents.setAdapter(sp_incidentAdapter);
recyclerViewIncidents.addOnItemTouchListener(new RecyclerItemClickListener(context,
new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
// TODO Handle item click
Log.v("item click", " working fine");
}
})
);
}
где вызывается initializeUI() ??? – sasikumar
Изменить 'R.id.recyclerView_Incidents' на' R.id.swipeRefreshLayout_Incidents' для 'SwipeRefreshLayout' –
@ ρяσѕρєяK Святое дерьмо !!! Какая глупость я сделал. В любом случае спасибо. – VVB