Recycler View不会迭代到数组的长度。这是代码,我缺少什么。我遵循了描述整个过程的指南,该指南在列表视图中可见数组的所有项目。这是承载recyclerView的主要活动文件,该文件位于适配器java类的下面,该适配器java类过滤整个数组并弹出View视图。请帮我PickupActivity.javapackage 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)); }}
2 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
⬇删除此代码⬇
public class StudentListAdapter extends RecyclerView.Adapter<StudentListAdapter.ViewHolder>
{
// ....
}
⬇使用此代码⬇
public class StudentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
// ....
}
因为您扩展了:-公共类StudentListAdapter
extends RecyclerView.Adapter<StudentListAdapter.ViewHolder>
并且在这里扩展:-公共类ViewHolder extends RecyclerView.ViewHolder
添加回答
举报
0/150
提交
取消