I am new to Android. I need to get a list of strings from a JSON list. It will be added to a Spinner
list. I have the list on server like
[{\"bgrou
Make the following model class (parcelable)
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example implements Parcelable {
@SerializedName("bgroup")
@Expose
private String bgroup;
public String getBgroup() {
return bgroup;
}
public void setBgroup(String bgroup) {
this.bgroup = bgroup;
}
protected Example(Parcel in) {
bgroup = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(bgroup);
}
@SuppressWarnings("unused")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@Override
public Example createFromParcel(Parcel in) {
return new Example(in);
}
@Override
public Example[] newArray(int size) {
return new Example[size];
}
};
}
Than create interface class like this
public interface ApiService {
@GET("")
Call> getBloodGroups();
}
And finally call retrofit like following :
Call> call = new RestClient(this).getApiService()
.getBloodGroups();
call.enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
}
@Override
public void onFailure(Call> call, Throwable throwable) {
}
});