我想问一下如何在片段
中应用recyclerview我正在使用BottomNavigationView和Fragment,我想在第一个片段中安装recyclerview,我很困惑,因为它太难了,我尝试了很多次,但它总是一个错误
我希望你们能帮助我
我的ItemOneFragment
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_item_one, container, false);
List<ItemObject> rowListItem = getAllItemList();
lLayout = new LinearLayoutManager(MainActivity.this);
RecyclerView rView = (RecyclerView)v.findViewById(R.id.recycler_view);
rView.setLayoutManager(lLayout);
RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(MainActivity.this, rowListItem);
rView.setAdapter(rcAdapter);
return v;
}
private List<ItemObject> getAllItemList(){
List<ItemObject> allItems = new ArrayList<ItemObject>();
allItems.add(new ItemObject("United States", R.drawable.newyork));
allItems.add(new ItemObject("Canada", R.drawable.canada));
allItems.add(new ItemObject("United Kingdom", R.drawable.uk));
allItems.add(new ItemObject("Germany", R.drawable.germany));
allItems.add(new ItemObject("Sweden", R.drawable.sweden));
return allItems;
}
}