我想在getDaystime()
中获取所有TextView
,但目前只显示最后一个getDaystime()
。以下是我到目前为止的情况:
List<WeekDays> weekDaysList = place.getWeekDayList();
if(weekDaysList.size()>0)
{
for(int i = 0;i<weekDaysList.size();i++)
{
WeekDays days = weekDaysList.get(i);
//String openhours += days.getDaystime();
//Log.d("WeekDaysView",days.getDaystime());
weekDays.setText(days.getDaystime());
}
}
以下是logcat结果:
11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:星期一:上午9:00 - 下午7:00 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周二:上午9:00 - 下午7:00 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周三:9:00 AM - 7:00 PM 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周四:上午9:00 - 下午7:00 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周五:上午9:00 - 下午7:00 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周六:9:00 AM - 7:00 PM 11-23 17:24:55.553 32297-32297 / com.softtoll.ncf D / WeekDaysView:周日:关闭
答案 0 :(得分:1)
那是因为你使用的是TextView.setText()
方法。尝试使用TextView.append()
方法。
答案 1 :(得分:1)
你应该使用
append(CharSequence text)
将指定文本附加到
TextView's
显示缓冲区的便捷方法,如果它尚未可编辑,则将其升级为EDITABLE。
使用此
weekDays.append(days.getDaystime()+" \n");
而不是
weekDays.setText(days.getDaystime());
或使用
StringBuilder
if(weekDaysList.size()>0)
{
StringBuilder myString = new StringBuilder();
for(int i = 0;i<weekDaysList.size();i++)
{
WeekDays days = weekDaysList.get(i);
myString.append(days.getDaystime()+ " \n");
}
weekDays.setText(myString);
}
别忘了设置
textView.setMaxLines(int lines);
属性
答案 2 :(得分:1)
我认为您的textview是weekDays
因此,对于weekDays.setText(days.getDaystime());
,您将覆盖每个项目的文本。您可能希望在for循环中创建一个字符串,并在循环结束后设置文本或使用TextView.append()
方法。
答案 3 :(得分:0)
试试这个
List<WeekDays> weekDaysList = place.getWeekDayList();
if(weekDaysList.size()>0)
{
for(int i = 0;i<weekDaysList.size();i++)
{
WeekDays days = weekDaysList.get(i);
//String openhours += days.getDaystime();
//Log.d("WeekDaysView",days.getDaystime());
weekDays.append("WeekDaysView:\n" + days.getDaystime() + "\n");
}
}