猿问

Android Java中的回收视图

Recycler View不会迭代到数组的长度。这是代码,我缺少什么。我遵循了描述整个过程的指南,该指南在列表视图中可见数组的所有项目。这是承载recyclerView的主要活动文件,该文件位于适配器java类的下面,该适配器java类过滤整个数组并弹出View视图。请帮我


PickupActivity.java


package com.demo.driverconsole;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;

import android.support.v7.widget.RecyclerView;

import android.support.v7.widget.RecyclerViewAccessibilityDelegate;

import android.util.Log;

import android.widget.Adapter;

import android.widget.Toast;

import java.util.ArrayList;


public class pickupActivity extends AppCompatActivity {

    private static final String TAG = "pickupActivity";

    private RecyclerView studentList;

    private  RecyclerView.Adapter adapter;

    private RecyclerView.LayoutManager layoutManager;

    private ArrayList<String> myDataset = new ArrayList<>();

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_pickup);

        myDataset.add("John Doe");

        myDataset.add("Jane Doe");

        myDataset.add("Susan");

        initRecycler();


    }


    public void initRecycler() {

        Log.d(TAG, "Called");

        RecyclerView recyclerView = findViewById(R.id.recyclerView);

        StudentListAdapter adapter = new StudentListAdapter(myDataset);

        recyclerView.setAdapter(adapter);

        recyclerView.setLayoutManager(new LinearLayoutManager(this));

    }

}


凤凰求蛊
浏览 114回答 2
2回答

江户川乱折腾

⬇删除此代码⬇public class StudentListAdapter extends RecyclerView.Adapter<StudentListAdapter.ViewHolder>{&nbsp; &nbsp; // ....}⬇使用此代码⬇public class StudentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // ....&nbsp; &nbsp; }因为您扩展了:-公共类StudentListAdapterextends RecyclerView.Adapter<StudentListAdapter.ViewHolder>并且在这里扩展:-公共类ViewHolder extends RecyclerView.ViewHolder
随时随地看视频慕课网APP

相关分类

Java
我要回答