How to Load a Json data into dropdown Spinner Using Android Fragments












0















I need to Show Registration Form With Spinner Using Fragments and get the data using Json



This is kind of register form. At the bottom we have change language button which will reset the form and will be shown in arabic / english.



[  
{
"Id":1,
"TitleEN":"Kuwait",
"TitleAR":"الكويت",
"CurrencyId":1,
"CurrencyEN":"Kuwaiti Dinar",
"CurrencyAR":"دينار كويتى",
"CodeEN":"KWD",
"CodeAR":"د.ك",
"Code":"965"
},
{
"Id":2,
"TitleEN":"Emirates",
"TitleAR":"الإمارات",
"CurrencyId":2,
"CurrencyEN":"Emirati Dirham",
"CurrencyAR":"درهم إماراتي",
"CodeEN":"AED",
"CodeAR":"درهم",
"Code":"971"
},
{
"Id":3,
"TitleEN":"Saudi Arabia",
"TitleAR":"السعودية",
"CurrencyId":3,
"CurrencyEN":"Saudi Riyal",
"CurrencyAR":"ريال سعودى",
"CodeEN":"SAR",
"CodeAR":"ر.س",
"Code":"966"
}
]









share|improve this question

























  • What have you done up until now?

    – Tamir Abutbul
    Dec 31 '18 at 11:58











  • which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

    – Raza
    Jan 1 at 6:29
















0















I need to Show Registration Form With Spinner Using Fragments and get the data using Json



This is kind of register form. At the bottom we have change language button which will reset the form and will be shown in arabic / english.



[  
{
"Id":1,
"TitleEN":"Kuwait",
"TitleAR":"الكويت",
"CurrencyId":1,
"CurrencyEN":"Kuwaiti Dinar",
"CurrencyAR":"دينار كويتى",
"CodeEN":"KWD",
"CodeAR":"د.ك",
"Code":"965"
},
{
"Id":2,
"TitleEN":"Emirates",
"TitleAR":"الإمارات",
"CurrencyId":2,
"CurrencyEN":"Emirati Dirham",
"CurrencyAR":"درهم إماراتي",
"CodeEN":"AED",
"CodeAR":"درهم",
"Code":"971"
},
{
"Id":3,
"TitleEN":"Saudi Arabia",
"TitleAR":"السعودية",
"CurrencyId":3,
"CurrencyEN":"Saudi Riyal",
"CurrencyAR":"ريال سعودى",
"CodeEN":"SAR",
"CodeAR":"ر.س",
"Code":"966"
}
]









share|improve this question

























  • What have you done up until now?

    – Tamir Abutbul
    Dec 31 '18 at 11:58











  • which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

    – Raza
    Jan 1 at 6:29














0












0








0








I need to Show Registration Form With Spinner Using Fragments and get the data using Json



This is kind of register form. At the bottom we have change language button which will reset the form and will be shown in arabic / english.



[  
{
"Id":1,
"TitleEN":"Kuwait",
"TitleAR":"الكويت",
"CurrencyId":1,
"CurrencyEN":"Kuwaiti Dinar",
"CurrencyAR":"دينار كويتى",
"CodeEN":"KWD",
"CodeAR":"د.ك",
"Code":"965"
},
{
"Id":2,
"TitleEN":"Emirates",
"TitleAR":"الإمارات",
"CurrencyId":2,
"CurrencyEN":"Emirati Dirham",
"CurrencyAR":"درهم إماراتي",
"CodeEN":"AED",
"CodeAR":"درهم",
"Code":"971"
},
{
"Id":3,
"TitleEN":"Saudi Arabia",
"TitleAR":"السعودية",
"CurrencyId":3,
"CurrencyEN":"Saudi Riyal",
"CurrencyAR":"ريال سعودى",
"CodeEN":"SAR",
"CodeAR":"ر.س",
"Code":"966"
}
]









share|improve this question
















I need to Show Registration Form With Spinner Using Fragments and get the data using Json



This is kind of register form. At the bottom we have change language button which will reset the form and will be shown in arabic / english.



[  
{
"Id":1,
"TitleEN":"Kuwait",
"TitleAR":"الكويت",
"CurrencyId":1,
"CurrencyEN":"Kuwaiti Dinar",
"CurrencyAR":"دينار كويتى",
"CodeEN":"KWD",
"CodeAR":"د.ك",
"Code":"965"
},
{
"Id":2,
"TitleEN":"Emirates",
"TitleAR":"الإمارات",
"CurrencyId":2,
"CurrencyEN":"Emirati Dirham",
"CurrencyAR":"درهم إماراتي",
"CodeEN":"AED",
"CodeAR":"درهم",
"Code":"971"
},
{
"Id":3,
"TitleEN":"Saudi Arabia",
"TitleAR":"السعودية",
"CurrencyId":3,
"CurrencyEN":"Saudi Riyal",
"CurrencyAR":"ريال سعودى",
"CodeEN":"SAR",
"CodeAR":"ر.س",
"Code":"966"
}
]






java android json android-fragments retrofit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 7:46







Kaliraj

















asked Dec 31 '18 at 7:37









KalirajKaliraj

12




12













  • What have you done up until now?

    – Tamir Abutbul
    Dec 31 '18 at 11:58











  • which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

    – Raza
    Jan 1 at 6:29



















  • What have you done up until now?

    – Tamir Abutbul
    Dec 31 '18 at 11:58











  • which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

    – Raza
    Jan 1 at 6:29

















What have you done up until now?

– Tamir Abutbul
Dec 31 '18 at 11:58





What have you done up until now?

– Tamir Abutbul
Dec 31 '18 at 11:58













which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

– Raza
Jan 1 at 6:29





which spinner has to show the json data ? there are multiple spinners. code, country city area. which one has to show the data?

– Raza
Jan 1 at 6:29












1 Answer
1






active

oldest

votes


















0














Note.I assume you have followed the first 3 steps from this [question][1]
and will start from the following
Step 1
Add spinner in xml



 <Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title" />


Step 2
In ApiInterface Class add the following code



@GET("/app/app.asmx/GetCountries")
Call<List<Country>> getCountry();


Step 3
Create new model class by name Country



public class Country {

@SerializedName("Id")
@Expose
private Integer id;
@SerializedName("TitleEN")
@Expose
private String titleEN;
@SerializedName("TitleAR")
@Expose
private String titleAR;
@SerializedName("CurrencyId")
@Expose
private Integer currencyId;
@SerializedName("CurrencyEN")
@Expose
private String currencyEN;
@SerializedName("CurrencyAR")
@Expose
private String currencyAR;
@SerializedName("CodeEN")
@Expose
private String codeEN;
@SerializedName("CodeAR")
@Expose
private String codeAR;
@SerializedName("Code")
@Expose
private String code;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitleEN() {
return titleEN;
}

public void setTitleEN(String titleEN) {
this.titleEN = titleEN;
}

public String getTitleAR() {
return titleAR;
}

public void setTitleAR(String titleAR) {
this.titleAR = titleAR;
}

public Integer getCurrencyId() {
return currencyId;
}

public void setCurrencyId(Integer currencyId) {
this.currencyId = currencyId;
}

public String getCurrencyEN() {
return currencyEN;
}

public void setCurrencyEN(String currencyEN) {
this.currencyEN = currencyEN;
}

public String getCurrencyAR() {
return currencyAR;
}

public void setCurrencyAR(String currencyAR) {
this.currencyAR = currencyAR;
}

public String getCodeEN() {
return codeEN;
}

public void setCodeEN(String codeEN) {
this.codeEN = codeEN;
}

public String getCodeAR() {
return codeAR;
}

public void setCodeAR(String codeAR) {
this.codeAR = codeAR;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

}


Step 4
find view in activity or fragment and add call the request and get response and add the response in spinner adapter.Initialize a string list out side the onCreate method



List<String> codes = new ArrayList<String>();
APIInterface apiInterfacePages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
apiInterfacePages= PageApiClient.getRetrofit().create(APIInterface.class);
Call<List<Country>> getCountry = apiInterfacePages.getCountry();
getCountry.enqueue(new Callback<List<Country>>() {
@Override
public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {
countryList = response.body();
for (int i = 0; i < countryList.size(); i++) {
codes.add(countryList.get(i).getCode());

}
ArrayAdapter<String> adapterTime = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, codes);
spinner.setAdapter(adapterTime);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "" + countryList.get(i).getTitleEN(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

@Override
public void onFailure(Call<List<Country>> call, Throwable t) {

}
});
}





share|improve this answer


























  • @Kaliraj check the updated answer

    – Raza
    Jan 1 at 9:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53984840%2fhow-to-load-a-json-data-into-dropdown-spinner-using-android-fragments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Note.I assume you have followed the first 3 steps from this [question][1]
and will start from the following
Step 1
Add spinner in xml



 <Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title" />


Step 2
In ApiInterface Class add the following code



@GET("/app/app.asmx/GetCountries")
Call<List<Country>> getCountry();


Step 3
Create new model class by name Country



public class Country {

@SerializedName("Id")
@Expose
private Integer id;
@SerializedName("TitleEN")
@Expose
private String titleEN;
@SerializedName("TitleAR")
@Expose
private String titleAR;
@SerializedName("CurrencyId")
@Expose
private Integer currencyId;
@SerializedName("CurrencyEN")
@Expose
private String currencyEN;
@SerializedName("CurrencyAR")
@Expose
private String currencyAR;
@SerializedName("CodeEN")
@Expose
private String codeEN;
@SerializedName("CodeAR")
@Expose
private String codeAR;
@SerializedName("Code")
@Expose
private String code;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitleEN() {
return titleEN;
}

public void setTitleEN(String titleEN) {
this.titleEN = titleEN;
}

public String getTitleAR() {
return titleAR;
}

public void setTitleAR(String titleAR) {
this.titleAR = titleAR;
}

public Integer getCurrencyId() {
return currencyId;
}

public void setCurrencyId(Integer currencyId) {
this.currencyId = currencyId;
}

public String getCurrencyEN() {
return currencyEN;
}

public void setCurrencyEN(String currencyEN) {
this.currencyEN = currencyEN;
}

public String getCurrencyAR() {
return currencyAR;
}

public void setCurrencyAR(String currencyAR) {
this.currencyAR = currencyAR;
}

public String getCodeEN() {
return codeEN;
}

public void setCodeEN(String codeEN) {
this.codeEN = codeEN;
}

public String getCodeAR() {
return codeAR;
}

public void setCodeAR(String codeAR) {
this.codeAR = codeAR;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

}


Step 4
find view in activity or fragment and add call the request and get response and add the response in spinner adapter.Initialize a string list out side the onCreate method



List<String> codes = new ArrayList<String>();
APIInterface apiInterfacePages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
apiInterfacePages= PageApiClient.getRetrofit().create(APIInterface.class);
Call<List<Country>> getCountry = apiInterfacePages.getCountry();
getCountry.enqueue(new Callback<List<Country>>() {
@Override
public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {
countryList = response.body();
for (int i = 0; i < countryList.size(); i++) {
codes.add(countryList.get(i).getCode());

}
ArrayAdapter<String> adapterTime = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, codes);
spinner.setAdapter(adapterTime);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "" + countryList.get(i).getTitleEN(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

@Override
public void onFailure(Call<List<Country>> call, Throwable t) {

}
});
}





share|improve this answer


























  • @Kaliraj check the updated answer

    – Raza
    Jan 1 at 9:23
















0














Note.I assume you have followed the first 3 steps from this [question][1]
and will start from the following
Step 1
Add spinner in xml



 <Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title" />


Step 2
In ApiInterface Class add the following code



@GET("/app/app.asmx/GetCountries")
Call<List<Country>> getCountry();


Step 3
Create new model class by name Country



public class Country {

@SerializedName("Id")
@Expose
private Integer id;
@SerializedName("TitleEN")
@Expose
private String titleEN;
@SerializedName("TitleAR")
@Expose
private String titleAR;
@SerializedName("CurrencyId")
@Expose
private Integer currencyId;
@SerializedName("CurrencyEN")
@Expose
private String currencyEN;
@SerializedName("CurrencyAR")
@Expose
private String currencyAR;
@SerializedName("CodeEN")
@Expose
private String codeEN;
@SerializedName("CodeAR")
@Expose
private String codeAR;
@SerializedName("Code")
@Expose
private String code;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitleEN() {
return titleEN;
}

public void setTitleEN(String titleEN) {
this.titleEN = titleEN;
}

public String getTitleAR() {
return titleAR;
}

public void setTitleAR(String titleAR) {
this.titleAR = titleAR;
}

public Integer getCurrencyId() {
return currencyId;
}

public void setCurrencyId(Integer currencyId) {
this.currencyId = currencyId;
}

public String getCurrencyEN() {
return currencyEN;
}

public void setCurrencyEN(String currencyEN) {
this.currencyEN = currencyEN;
}

public String getCurrencyAR() {
return currencyAR;
}

public void setCurrencyAR(String currencyAR) {
this.currencyAR = currencyAR;
}

public String getCodeEN() {
return codeEN;
}

public void setCodeEN(String codeEN) {
this.codeEN = codeEN;
}

public String getCodeAR() {
return codeAR;
}

public void setCodeAR(String codeAR) {
this.codeAR = codeAR;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

}


Step 4
find view in activity or fragment and add call the request and get response and add the response in spinner adapter.Initialize a string list out side the onCreate method



List<String> codes = new ArrayList<String>();
APIInterface apiInterfacePages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
apiInterfacePages= PageApiClient.getRetrofit().create(APIInterface.class);
Call<List<Country>> getCountry = apiInterfacePages.getCountry();
getCountry.enqueue(new Callback<List<Country>>() {
@Override
public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {
countryList = response.body();
for (int i = 0; i < countryList.size(); i++) {
codes.add(countryList.get(i).getCode());

}
ArrayAdapter<String> adapterTime = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, codes);
spinner.setAdapter(adapterTime);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "" + countryList.get(i).getTitleEN(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

@Override
public void onFailure(Call<List<Country>> call, Throwable t) {

}
});
}





share|improve this answer


























  • @Kaliraj check the updated answer

    – Raza
    Jan 1 at 9:23














0












0








0







Note.I assume you have followed the first 3 steps from this [question][1]
and will start from the following
Step 1
Add spinner in xml



 <Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title" />


Step 2
In ApiInterface Class add the following code



@GET("/app/app.asmx/GetCountries")
Call<List<Country>> getCountry();


Step 3
Create new model class by name Country



public class Country {

@SerializedName("Id")
@Expose
private Integer id;
@SerializedName("TitleEN")
@Expose
private String titleEN;
@SerializedName("TitleAR")
@Expose
private String titleAR;
@SerializedName("CurrencyId")
@Expose
private Integer currencyId;
@SerializedName("CurrencyEN")
@Expose
private String currencyEN;
@SerializedName("CurrencyAR")
@Expose
private String currencyAR;
@SerializedName("CodeEN")
@Expose
private String codeEN;
@SerializedName("CodeAR")
@Expose
private String codeAR;
@SerializedName("Code")
@Expose
private String code;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitleEN() {
return titleEN;
}

public void setTitleEN(String titleEN) {
this.titleEN = titleEN;
}

public String getTitleAR() {
return titleAR;
}

public void setTitleAR(String titleAR) {
this.titleAR = titleAR;
}

public Integer getCurrencyId() {
return currencyId;
}

public void setCurrencyId(Integer currencyId) {
this.currencyId = currencyId;
}

public String getCurrencyEN() {
return currencyEN;
}

public void setCurrencyEN(String currencyEN) {
this.currencyEN = currencyEN;
}

public String getCurrencyAR() {
return currencyAR;
}

public void setCurrencyAR(String currencyAR) {
this.currencyAR = currencyAR;
}

public String getCodeEN() {
return codeEN;
}

public void setCodeEN(String codeEN) {
this.codeEN = codeEN;
}

public String getCodeAR() {
return codeAR;
}

public void setCodeAR(String codeAR) {
this.codeAR = codeAR;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

}


Step 4
find view in activity or fragment and add call the request and get response and add the response in spinner adapter.Initialize a string list out side the onCreate method



List<String> codes = new ArrayList<String>();
APIInterface apiInterfacePages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
apiInterfacePages= PageApiClient.getRetrofit().create(APIInterface.class);
Call<List<Country>> getCountry = apiInterfacePages.getCountry();
getCountry.enqueue(new Callback<List<Country>>() {
@Override
public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {
countryList = response.body();
for (int i = 0; i < countryList.size(); i++) {
codes.add(countryList.get(i).getCode());

}
ArrayAdapter<String> adapterTime = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, codes);
spinner.setAdapter(adapterTime);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "" + countryList.get(i).getTitleEN(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

@Override
public void onFailure(Call<List<Country>> call, Throwable t) {

}
});
}





share|improve this answer















Note.I assume you have followed the first 3 steps from this [question][1]
and will start from the following
Step 1
Add spinner in xml



 <Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title" />


Step 2
In ApiInterface Class add the following code



@GET("/app/app.asmx/GetCountries")
Call<List<Country>> getCountry();


Step 3
Create new model class by name Country



public class Country {

@SerializedName("Id")
@Expose
private Integer id;
@SerializedName("TitleEN")
@Expose
private String titleEN;
@SerializedName("TitleAR")
@Expose
private String titleAR;
@SerializedName("CurrencyId")
@Expose
private Integer currencyId;
@SerializedName("CurrencyEN")
@Expose
private String currencyEN;
@SerializedName("CurrencyAR")
@Expose
private String currencyAR;
@SerializedName("CodeEN")
@Expose
private String codeEN;
@SerializedName("CodeAR")
@Expose
private String codeAR;
@SerializedName("Code")
@Expose
private String code;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitleEN() {
return titleEN;
}

public void setTitleEN(String titleEN) {
this.titleEN = titleEN;
}

public String getTitleAR() {
return titleAR;
}

public void setTitleAR(String titleAR) {
this.titleAR = titleAR;
}

public Integer getCurrencyId() {
return currencyId;
}

public void setCurrencyId(Integer currencyId) {
this.currencyId = currencyId;
}

public String getCurrencyEN() {
return currencyEN;
}

public void setCurrencyEN(String currencyEN) {
this.currencyEN = currencyEN;
}

public String getCurrencyAR() {
return currencyAR;
}

public void setCurrencyAR(String currencyAR) {
this.currencyAR = currencyAR;
}

public String getCodeEN() {
return codeEN;
}

public void setCodeEN(String codeEN) {
this.codeEN = codeEN;
}

public String getCodeAR() {
return codeAR;
}

public void setCodeAR(String codeAR) {
this.codeAR = codeAR;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

}


Step 4
find view in activity or fragment and add call the request and get response and add the response in spinner adapter.Initialize a string list out side the onCreate method



List<String> codes = new ArrayList<String>();
APIInterface apiInterfacePages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
apiInterfacePages= PageApiClient.getRetrofit().create(APIInterface.class);
Call<List<Country>> getCountry = apiInterfacePages.getCountry();
getCountry.enqueue(new Callback<List<Country>>() {
@Override
public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {
countryList = response.body();
for (int i = 0; i < countryList.size(); i++) {
codes.add(countryList.get(i).getCode());

}
ArrayAdapter<String> adapterTime = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, codes);
spinner.setAdapter(adapterTime);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "" + countryList.get(i).getTitleEN(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

@Override
public void onFailure(Call<List<Country>> call, Throwable t) {

}
});
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 9:22

























answered Jan 1 at 7:13









RazaRaza

25912




25912













  • @Kaliraj check the updated answer

    – Raza
    Jan 1 at 9:23



















  • @Kaliraj check the updated answer

    – Raza
    Jan 1 at 9:23

















@Kaliraj check the updated answer

– Raza
Jan 1 at 9:23





@Kaliraj check the updated answer

– Raza
Jan 1 at 9:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53984840%2fhow-to-load-a-json-data-into-dropdown-spinner-using-android-fragments%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas