我遇到了我的listView问题,并从中获取正确的项目。 我的应用程序是一个管理员应用程序,允许教师为特定学生添加课程笔记。我的情况如下:Android:尝试使用listView访问独特的ID
当老师增加了一个新的教训音符,它会自动给它一个唯一的ID
使学生1(ID 1)具有课名单与IDS指出:1,3,4 4,5和6
学生2(ID 2)具有课注意到IDS:2,7,8和9
学生1具有的列表视图:1,2,3,4,5
学生2有列表视图:1,2,3,4,5
所以,当学生1访问注意事项1,查询如下:SELECT * FROM table_lessons其中lessonID = 1和StudentID = 1
注2:SELECT * FROM table_lessons其中lessonID = 2和StudentID = 1
注3:从table_lessons选择*其中lessonID = 3和StudentID = 1
等等....
但是你看那个学生1不具备的教训记 '2' - 这样的程序崩溃
我觉得ListView控件的位置离扔程序...
这是在我的lessonNotesList类:(修订版)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lesson_notes_list);
Button backToMain = (Button)findViewById(R.id.backToMain);
backToMain.setOnClickListener(this);
Bundle extras = getIntent().getExtras();
dyslexiaDb = new DBHelper(this);
ArrayList array_list = dyslexiaDb.getAllStudents();
//Creating an ArrayList of contacts data
//ArrayAdapter arrayAdapter = new ArrayAdapter(this,R.layout.list_layout, array_list);
LessonAdapter adapter = new LessonAdapter(array_list);
ListView listView = new ListView(this);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
// the id parameter returns the adapter's getItemId method
//intent.putExtra("lesson_id", id);
}
});
}
LessonAdapter类:
public class LessonAdapter extends BaseAdapter{
private ArrayList<LessonNotesData> lessonNotes;
public LessonAdapter(ArrayList<LessonNotesData> lessonNotes) {
this.lessonNotes = lessonNotes;
}
@Override
public int getCount(){
// get the number of lessons stored in the array
return lessonNotes.size();
}
@Override
public LessonNotesData getItem(int item){
// return the lesson object
return lessonNotes.get(item);
}
@Override
public long getItemId(int item){
// return the lessonNotes id
return getItem(item).getLessonID();
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// inflate the layout item you want to use
view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.activity_lesson_notes_list, viewGroup, false);
//((TextView) view.findViewById(R.id.listViewMain)).setText(getItem(i).getDate());
return view;
}
}
activity_lesson_notes_list .xml
谢谢