Android:从地图的arraylist中获取值

时间:2014-09-26 18:40:19

标签: android database arraylist map

照片网址链接,标题,用户名从Parse加载并打包为地图,然后地图存储为arraylist,如下所示:

public class Photos 
{
    private String user_name;
    private String photo_title;
    private String photo_ref;   

    public void set_user_name(String name) {this.user_name = name;}
    public void set_photo_ref(String photo_ref) {this.photo_ref = photo_ref;}
    public void set_photo_title(String photo_title) {this.photo_title = photo_title;}

    public String get_user_name() {return user_name;}
    public String get_photo_ref() {return photo_ref;}
    public String get_photo_title() {return photo_title;}
}

然后从Parse下载数据库,

            for (ParseObject photo_data : ob) 
            {
                ParseFile image = (ParseFile) photo_data.get("photo_file");
                Photos map = new Photos();

                String photo_url = image.getUrl();                                  map.set_photo_ref(photo_url);
                int photo_id = (Integer) photo_data.get("photo_id");                map.set_photo_id(photo_id);             
                String status = (String)  photo_data.get("status");                 map.set_photo_status(status);           
                String photo_user_name = (String) photo_data.get("user_name");      map.set_user_name(photo_user_name);     
                String photo_title = (String) photo_data.get("photo_title");    

                if (status.equals("accepted"))
                {                   
                    map_all_info_photoarraylist.add(map);
                }   

问题:

如何使用方法photo_ref

从上面的地图中提取,我怎么能创建另一个get_photo_ref()的字符串数组?
        String[] stockArr = new String[map_all_info_photoarraylist.size()];
        stockArr = map_all_info_photoarraylist.???????.toArray(stockArr);

谢谢!

1 个答案:

答案 0 :(得分:0)

如果你想要一个数组:

 String[] stockArr = new String[map_all_info_photoarraylist.size()];
          for(int i =0; i<map_all_info_photoarraylist.size(); i++){
              stockArr[i] = map_all_info_photoarraylist.get(i).get_photo_ref();
           }