У меня ошибка на моем LinearLayoutManager
, когда я запускаю этот код, он говорит:
error: incompatible types: NotificationFragment cannot be converted to Context
Вот мой код NotificationFragment.java
public class NotificationFragment extends Fragment {
private RecyclerView recyclerView;
private NotificationAdapter adapter;
private ArrayList<NotificationModel> notificationModelArrayList;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_notification,container,false);
addData();
recyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
adapter = new NotificationAdapter(notificationModelArrayList);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(NotificationFragment.this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
}
void addData(){
notificationModelArrayList = new ArrayList<>();
notificationModelArrayList.add(new NotificationModel("Event 1", "1 January 2019", "Surabaya"));
notificationModelArrayList.add(new NotificationModel("Event 2", "1 January 2019", "Surabaya"));
notificationModelArrayList.add(new NotificationModel("Event 3", "1 January 2019", "Surabaya"));
notificationModelArrayList.add(new NotificationModel("Event 4", "1 January 2019", "Surabaya"));
}
}
Ошибка включена
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(NotificationFragment.this);
Надеюсь, вы сможете мне помочь, спасибо.