This is my response and I am trying to get into my spinner but its not showing can any one tell me what is mistake in my code..my snippet code is given below..and i also added response..Thanks in advance and sorry for bad English
{
"status":"success",
"country_list":
[
{
"country_id":237,
"name":"Zimbabwe"
},
{
"country_id":236,
"name":"Zambia"
}
]
}
class Country extends AsyncTask<String, String, ArrayList<HashMap<String,String>>> {
ArrayAdapter<String> adaptercountry ;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MyFragment.this.getActivity());
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected ArrayList<HashMap<String,String>> doInBackground(String... args) {
ServiceHandler sh = new ServiceHandler();
data = new ArrayList<HashMap<String, String>>();
String jsonStr = sh.makeServiceCall(COUNTRY_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
country_list = jsonObj.getJSONArray(COUNTRY_LIST);
for (int i = 0; i < country_list.length(); i++) {
JSONObject c = country_list.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put(COUNTRY_ID, c.getString(COUNTRY_ID));
map.put(COUNTRY_NAME,c.getString(COUNTRY_NAME));
data.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return data;
}
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
adaptercountry = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item);
spcountry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(getActivity())
.setTitle("Select")
.setAdapter(adaptercountry, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
spcountry.setText(adaptercountry.getItem(which).toString());
dialog.dismiss();
}
}).create().show();
}
});
}