将数据从ArrayList <string>发送到String Array(Android)</string>

时间:2014-08-16 09:16:11

标签: android string arraylist arrays

我正在开发一个app,我正在从url加载图像,所以我在ArrayList中保存了一些图像url,我想将它发送到String Array,这样我就可以加载图像了。

我正在尝试将数据从ArrayList发送到String Array但我没有在String Array中接收数据。

我试过这个:

package com.nostra13.example.universalimageloader;

import java.util.ArrayList;

public final class Constants {

    public static ArrayList<String> LIST = new ArrayList<String>();

    public static void main(String args[]) {
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
    }

    public static final String[] IMAGES = LIST.toArray(new String[LIST.size()]);

    private Constants() {

    }

    public static class Config {
        public static final boolean DEVELOPER_MODE = false;
    }

    public static class Extra {

        public static final String IMAGES = "com.nostra13.example.universalimageloader.IMAGES";
        public static final String IMAGE_POSITION = "com.nostra13.example.universalimageloader.IMAGE_POSITION";
    }

}

注意:如果你想建议我:那就不要。

public static final String[] IMAGES = new String[]{
        "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
        "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
        "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
    };

因为我的任务是将数据从ArrayList发送到String Array

2 个答案:

答案 0 :(得分:0)

public static ArrayList<String> LIST = new ArrayList<String>();
public static String[] IMAGES;
public static void main(String args[]) {
    LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
    LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
    LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
    IMAGES = LIST.toArray(new String[LIST.size()]);
}

答案 1 :(得分:0)

将列表更改为main方法中的数组

public static String[] IMAGES;

  public static void main(String args[]) {
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
        LIST.add("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q");
        IMAGES = LIST.toArray(new String[LIST.size()]);
    }