我为我的应用程序使用片段。我还使用了一个导航抽屉,它通过抽屉中的按钮打开片段。
我试图用它的适配器和数组列表为我的 recyclerview 显示一些基本的图像和文本。
我遇到的问题是我不知道如何修改代码以对我的片段使用 recyclerview,因为我看到的所有教程都不使用片段。
以下是我的活动代码:
public class secondActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout drawer;
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
ArrayList<exampleItemBooks> exampleList = new ArrayList<>();
exampleList.add(new exampleItemBooks(R.drawable.artofwar, "Line 1", "Line
2"));
exampleList.add(new exampleItemBooks(R.drawable.aristotle, "Line 3",
"Line 4"));
exampleList.add(new exampleItemBooks(R.drawable.caesarbook, "Line 5",
"Line 6"));
exampleList.add(new exampleItemBooks(R.drawable.platorepublic, "Line 7",
"Line 8"));
exampleList.add(new exampleItemBooks(R.drawable.senecaletters, "Line 9",
"Line 10"));
exampleList.add(new exampleItemBooks(R.drawable.thehistoryofmypeople,
"Line 11", "Line 12"));
exampleList.add(new exampleItemBooks(R.drawable.theprince, "Line 13",
"Line 14"));
exampleList.add(new exampleItemBooks(R.drawable.thritysixstrategems,
"Line 15", "Line 16"));
exampleList.add(new exampleItemBooks(R.drawable.medidations, "Line 17",
"Line 18"));
mRecyclerView = findViewById(R.id.recyclerViewBooks);
mRecyclerView.setHasFixedSize(false);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new exampleBooksAdapter(exampleList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
Toolbar toolbar = findViewById(R.id.toolbarMain);
setSupportActionBar(toolbar);
慕妹3242003
相关分类