학교 기획자 앱을 고집하려고합니다. 탭 레이아웃에 래핑 된 각 일의 ListView로 구현 된 시간표 개요가 있습니다. 따라서 사용자는 월요일에서 금요일 사이를 전환 할 수 있으며 특정 날짜에 대한 시간표를 가져옵니다.ArrayAdapter 및 ListView는 특정 항목 만 표시합니다.
public class TimetableAdapter extends ArrayAdapter<Lesson> {
private List<Lesson> lessonList; // The model
...
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
...
view = inflater.inflate(R.layout.timetable_row, null);
Lesson currentLesson = lessonList.get(position);
// Checks if selected Tab (context.getDay()) correspondends to
// currentLesson's day. If so the lesson will be rendered into
// the appropriated ListView. So if the user selects the Monday Tab
// he only wants to see the lessons for Monday.
if (context.getDay() == currentLesson.getWeekDay().getWeekDay()) {
fillView(currentLesson, holder); // render Lesson
}
...
return view;
}
private void fillView(Lesson currentLesson, ViewHolder holder) {
holder.subject.setText(currentLesson.getSubject().getName());
}
public class TimetableActivity extends Activity implements OnTabChangeListener {
public void onCreate(Bundle savedInstanceState) {
....
timetableAdapter = new TimetableAdapter(this, getModel());
}
private List<Lesson> getModel() {
return timetable.getLessons();
}
public void onTabChanged(String tabId) {
currentTabName = tabId;
if (tabId.equals("tabMonday")) {
setCurrentListView(mondayListView);
}
else if (tabId.equals("tabTuesday")) {
// Checks tabTuesday and so on....
...
}
}
private void addLesson() {
timetable.addLesson(new Lesson(blabla(name, weekday etc.))); // blabla = user specified values
timetableAdapter.notifyDataSetChanged();
}
기본적으로 사용자가 수업을 추가하면 해당 평일, 이름 등의 매개 변수를 지정합니다. 이것은 blabla로 표시됩니다.
문제는 내가 데이터에 대해 하나의 ArrayList 만 사용하기 때문에 월요일 또는 화요일에 수업에 있습니다. 왜냐하면 getView(...)
이 lessonList의 각 항목에 대해 호출되고 평일이 원하는 것이 아닌 경우 new View()
을 반환하기 때문에 Monday의 경우 ListenerView는 빈 행으로 렌더링됩니다.
하나의 솔루션은 적절한 평일에 대해 5 개의 ArrayLists 및 5 개의 ArrayAdapter를 생성 할 수 있습니다. 따라서 월요일 수업은 ArrayList mondayList
이며 어댑터는이 목록에 바인딩됩니다. 그러나 이것은 다소 융통성이 없습니다. 더 좋은 솔루션이 있습니까?
미리 감사드립니다.
확인. 고맙습니다. 이 솔루션은 비교적 구현하기 쉽습니다. 나는 그것을 시도 할 것이다. – r6203
그런데 개체의 전체 복사본이 아니라 참조를 복사하면됩니다. –