通常,android微调器将提供一种从值列表中选择一项的快速方法,当我们单击或点击它时,它将显示一个包含所有值列表的下拉菜单。默认情况下,Android微调器将显示其当前选定的值,通过使用Adapter,我们可以将项目绑定到微调器对象。
ArrayList CaregoryID = new ArrayList();
ArrayList Category = new ArrayList();
ArrayAdapter categoryAdapter;
============================================================
HashMap<String, String> map = new HashMap<>();
map.put("token", "");
map.put("u_id", "");
CaregoryID.add("0");
Category.add("Select Category");
appDialogs.showProgressDialog();
callAPiActivity.doPost((Activity) mContext,Constant.URL, new GetApiResult() {
@Override
public void onSuccesResult(JSONObject result) throws JSONException {
appDialogs.hideProgressDialog();
JSONArray countryArray = result.getJSONArray("data");
for (int i = 0; i < countryArray.length(); i++) {
JSONObject countryObj = countryArray.getJSONObject(i);
CaregoryID.add(countryObj.getString("id"));
Category.add(countryObj.getString("abc"));
}
categoryAdapter = new ArrayAdapter(mContext, R.layout.simple_spinner_item, Category);
categoryAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
spinnerCategory.setAdapter(categoryAdapter);
}
@Override
public void onFailureResult(String messgae) throws JSONException {
appDialogs.hideProgressDialog();
appDialogs.setErrorToast(messgae);
}
@Override
public void onNetworkRetry(String message) throws JSONException {
}
});