我需要访问activity的ArrayList对象,以获得要显示在可扩展列表视图上的值。
public static HashMap<String, List<String>> getData() {
    //here i need access the arraylist object
    HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
    List<String>  size = new ArrayList<String>();
    size.add("Regular");
    size.add("Large");
    List<String> Addons = new ArrayList<String>();
    Addons.add("one small cheese");
    Addons.add("chicken");
    expandableListDetail.put("Choice of Size", size);
    expandableListDetail.put("Choice of Add ons", Addons);
    return expandableListDetail;
}发布于 2019-11-21 07:24:38
您有一个静态函数,并且需要在静态方法中访问活动类的普通ArrayList对象,因此,静态关键字的规则是,如果您有静态函数,那么静态函数中的所有成员都必须是静态的。
对于您的情况,您需要对活动类的ArrayList对象进行静态设置,然后再尝试。
https://stackoverflow.com/questions/58968315
复制相似问题