如何加载JSON数据到Android上微调? [英] How to load Json data into a spinner in Android?

查看:137
本文介绍了如何加载JSON数据到Android上微调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从装载到一个List&LT服务器中的数据;>,但无法获得具体项目

I can get the data from the server loaded into a List<>, but can't get the specific items.

JSON数据看起来是这样的。

Json data looks like this.

[
    {"subscriptionType":"1234,
    "typeName":"stuff",
    "name":"Alpha"},

    {"subscriptionType":"1234,
    "typeName":"stuff",
    "name":"Beta"},
]

等等...

我有我调用获取事件的数据加载到从presenter类。所有这一切似乎是工作,因为我得到一个登录加载到阵列中的数据

I have a class that that I load the data into from a Presenter calling a Fetch event. All that seems to be working because I get a Log for the data loaded into the Array

public class AppEntitySubscriptions implements Parcelable {


public AppEntitySubscriptions(ApiSubscription apiSubscription) {

    this.subscriptionType = apiSubscription.getSubscriptionType();
    this.typeName = apiSubscription.getTypeName();
    this.name = apiSubscription.getName();
}


private int subscriptionType;

private String typeName;

private String name;


public

int getSubscriptionType() {
    return subscriptionType;
}

public String getTypeName() {
    return typeName;
}

public String getName() {
    return name;
}

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.subscriptionType);
    dest.writeString(this.typeName);
    dest.writeString(this.name);
}

@SuppressWarnings("ResourceType")
protected AppEntitySubscriptions(Parcel in) {
    this.subscriptionType = in.readInt();
    this.typeName = in.readString();
    this.name = in.readString();
}

public static final Creator<AppEntitySubscriptions> CREATOR = new Creator<AppEntitySubscriptions>() {
    @Override
    public AppEntitySubscriptions createFromParcel(Parcel in) {
        return new AppEntitySubscriptions(in);
    }

    @Override
    public AppEntitySubscriptions[] newArray(int size) {
        return new AppEntitySubscriptions[size];
    }
};

现在这里是我迷路。我只是想为名的元素数据进入一个微调

Now here is where I am getting lost. I just want to get the data for "name" elements into a spinner

 Spinner spinner = (Spinner) findViewById(R.id.spinner);
 List<AppEntitySubscriptions> userSubscriptions;//data is here
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.toolbar_spinner_item, "what goes here"???);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

我不知道怎么弄的名字到它自己的字符串数组并加载到微调。任何建议将是有益的。

I don't know how to get the name into a string array of it's own and loaded into the spinner. Any suggestions would be helpful.

感谢。

推荐答案

您不能在微调使用此列表

private List<AppEntitySubscriptions> subscriptionsList = new ArrayList<>();

创建新列表

private List subscriptionsStrings = new ArrayList<>();

和填充它

for (int i=0; i<subscriptionsList.size(); i++) {
    subscriptionsStrings.add(subscriptionsList.get(i).getTypeName());
}

然后

ArrayAdapter<ArrayList<String>>(this, R.layout.toolbar_spinner_item, subscriptionsStrings);

这篇关于如何加载JSON数据到Android上微调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆