How can I make a spinner
show the names of x products of a JsonObject
that at the time I select, instead of sending me the name that I send the id of that product.
So I put what I want to show
private void getCategori(JSONObject j) throws JSONException {
Iterator<String> keys = j.keys();
while (keys.hasNext()) {
// obtiene el nombre del objeto.
String key = keys.next();
Log.i("Parser", "objeto : " + key);
JSONObject jsonObject1 = j.getJSONObject(key);
cate.add(jsonObject1.getString(Categorias.TAG_NAME));
cateid.add(jsonObject1.getString(Categorias.TAG_ID));
opciones1 = new String[]{cate_name};
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(prueba.this, android.R.layout.simple_spinner_item, cate);
scategory.setAdapter(adapter1);
scategory.setPrompt("Categorias");
}
and so I get the position of what is selected
private String getCatep(int position){
String c="";
try {
JSONArray jsonArray = new JSONArray();
jsonArray.put(returndatacategoria);
JSONObject json= jsonArray.getJSONObject(position);
c= json.getString(Categorias.TAG_ID);
} catch (JSONException e) {
e.printStackTrace();
}
return c;
}