Ich habe viele dieser Fragen gesehen, aber ich habe keine Kind-Elemente, so dass ich nicht weiß, warum das nicht richtig funktioniert. Ich habe dies in ein Fragment einer Aktivität verschoben und es funktioniert nicht mehr. Ich habe gesehen, dass vorherige Fragen Probleme mit Kindelementen aus der Recycleransicht haben, aber das ist hier nicht der Fall. Hier ist mein Code: RecyclerView hat keinen Layout-Manager
public class TodoListFragment extends Fragment {
@BindView(R.id.todo_recycler_view)
protected RecyclerView mRecyclerView;
@BindView(R.id.fab)
protected FloatingActionButton mFab;
private TodoListAdapter mTodoListAdapter;
private RecyclerView.LayoutManager mLayoutManager;
public static TodoListFragment newInstance() {
return new TodoListFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.todo_list_recycler_view, container, false);
ButterKnife.bind(this, view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mTodoListAdapter = new TodoListAdapter();
mRecyclerView.setAdapter(mTodoListAdapter);
return view;
}
@OnClick(R.id.fab)
public void onAdd() {
TodoItemView todoItemView = new TodoItemView(getContext());
todoItemView.setText("Schedule a dentist's appointment");
todoItemView.setTime(new Date());
mTodoListAdapter.addItem(todoItemView);
}
}
Und hier ist die todo_list_recycler_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/todo_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".presentation.TodoActivity"
tools:showIn="@layout/activity_todo_list" />
Jede Idee, warum ich diesen Fehler bin immer?
Caused by: java.lang.IllegalStateException: RecyclerView has no LayoutManager
at android.support.v7.widget.RecyclerView.generateLayoutParams(RecyclerView.java:3393)
at android.view.LayoutInflater.inflate(LayoutInflater.java:502)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.vorple.shortlist.shortlist.presentation.TodoListFragment.onCreateView(TodoListFragment.java:44)
Können Sie Ihren Adapter wenn möglich hinzufügen? Ich muss in meinem PC laufen. –
Sicher, hier ist es hier: http://pastebin.com/qC40tieM – user3496380
Und falls Sie das Modellobjekt benötigen: http://pastebin.com/5GQiwuqf – user3496380