我是android开发的新手,所以我对动态列表有疑问。
我有一个 Habit 类和 HabitMemoryDao 类,我想用 Habits 在主类中创建一个 ListView。有人可以编写 Listview 将显示所有习惯的主类吗?谢谢
public class Habit {
private String name;
private Date startDate;
private int duration;
private int frequencyInWeek; // from 1 to 7
private String awardText;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public int getFrequencyInWeek() {
return frequencyInWeek;
}
public void setFrequencyInWeek(int frequency) {
this.frequencyInWeek = frequency;
}
public String getAward() {
return awardText;
}
public void setAward(String award) {
this.awardText = award;
}
}
public class HabitMemoryDao {
private List<Habit> habitList = new LinkedList<Habit>();
public HabitMemoryDao() {
Habit habit1 = new Habit();
habit1.setName("Running");
habit1.setDuration(30);
habit1.setFrequencyInWeek(2);
habit1.setStartDate(new Date());
habitList.add(habit1);
Habit habit2 = new Habit();
habit2.setName("Swimming");
habit2.setDuration(15);
habit2.setFrequencyInWeek(7);
habit2.setStartDate(new Date());
habitList.add(habit2);
}
public List<Habit> getHabitList() {
return habitList;
}