我正在尝试使用自定义适配器在ArrayList中显示SQLite表的数据。如果我在未指定ID的情况下调用对象,则会使所有对象显示在列表中,但是当我使用getter方法时,仅返回列表中的第一项。
Activity.java
private void setCourseListView() {
final ArrayList<Course> mCourseList =
mDBHelper.getCourses(mTerm.getTermId());
CourseListAdapter mAdapter = new CourseListAdapter(this,mCourseList);
ListView mListView = findViewById(R.id.list_view_term_courses);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View
view, int position, long id) {
Course mCourse = (Course)
adapterView.getAdapter().getItem(position);
switchActivityCourse(CourseDetailsActivity.class, null,
mCourse);
}
}
);
}
我在onCreate()中有以下内容
mDBHelper = new DBOpenHelper(this);
Intent i = getIntent();
mTerm = mDBHelper.getTerm(((Term)
i.getSerializableExtra("term")).getTermId());