如何从ArrayList到setText进行weekdayText?

时间:2018-01-26 15:10:09

标签: android arrays arraylist

我试图获得" weekdayText"来自google place Api,我在改造中使用,这是我的classizenam来自类:Trip,我有serializeNam来对象和getter和setter:

@SerializedName("weekday_text")
@Expose
public List<Object> weekdayText = new ArrayList<Object>();

public List<Object> getWeekdayText() {
    return weekdayText;
}

public void setWeekdayText(List<Object> weekdayText) {
    this.weekdayText = weekdayText;

}

所以现在我把&#34; weekdayText&#34;在setText中,另一个类:TripDetails,我使用它的代码是:

private void UpdateUI(Trip trip) {
 mTextViewWeekday.setText(trip.getWeekdayText()+"");

当我在断点中使用时,我得到:

weekdayText = {ArrayList @ 6260} size = 0;

我该怎么做才能解决它?请帮我 :).. 非常感谢!

1 个答案:

答案 0 :(得分:0)

这是Java中的一个例子......

import java.util.ArrayList;
import java.util.List;

public class ModelExample {

        String weekdayText;

        public ModelExample(String weekdayText) {
            this.weekdayText = weekdayText;
        }

        public void setWeekdayText(String weekdayText){
            this.weekdayText = weekdayText;
        }

        public String getWeekdayText() {
            return this.weekdayText;
        }





    public static void main(String[] args) {
        // TODO Auto-generated method stub
          List<ModelExample> model = new ArrayList<ModelExample>();
          model.add(new ModelExample("Monday"));
          model.add(new ModelExample("Tuesday"));
          model.add(new ModelExample("Wednesday"));
          model.add(new ModelExample("Thursday"));
          model.add(new ModelExample("Friday"));
          model.add(new ModelExample("Saturday"));
          model.add(new ModelExample("Sunday"));

          System.out.println(model.size());

          for (int i = 0; i < model.size(); i++) {
              System.out.println(model.get(i).getWeekdayText());
          }

    }

}

输出如下。

  

7

     

周一

     

星期二

     

星期三

     

星期四

     

星期五

     星期六

     

星期日