i just made a connection with arraylist, but i want to show it into spinner. I already done it with recyclerview but this time i want to show only String "kode" (ITEMDATA0) in spinner adapter, and after choosing the String "kode" from spinner, the rest of the data (nama, sp1, sp2, etc) will showing in edittext under the spinner. Here is my form layout :
Here is my program :
private void showItem(){
list.clear();
JSONObject jsonObject = null;
//ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Item_Konfigurasi.TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
final String id = jo.getString(Item_Konfigurasi.TAG_ITEMXCODE);
final String kode = jo.getString(Item_Konfigurasi.TAG_ITEMDATA0);
final String nama = jo.getString(Item_Konfigurasi.TAG_ITEMDATA1);
final String sp1 = jo.getString(Item_Konfigurasi.TAG_ITEMDATA2);
final String sp2 = jo.getString(Item_Konfigurasi.TAG_ITEMDATA3);
final String ket = jo.getString(Item_Konfigurasi.TAG_ITEMDATA4);
HashMap<String,String> item = new HashMap<>();
item.put(Item_Konfigurasi.TAG_ITEMXCODE,id);
item.put(Item_Konfigurasi.TAG_ITEMDATA0,kode);
item.put(Item_Konfigurasi.TAG_ITEMDATA1,nama);
item.put(Item_Konfigurasi.TAG_ITEMDATA2,sp1);
item.put(Item_Konfigurasi.TAG_ITEMDATA3,sp2);
item.put(Item_Konfigurasi.TAG_ITEMDATA4,ket);
list.add(item);
}
//THIS WILL BE THE PLACE FOR CUSTOM SPINNER ADAPTER
/*CustomAdapter mAdapter = new CustomAdapter(Transaksi_Add.this,
R.layout.listspinnertransaksi_layout, R.id.title, list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
mRecyclerView.setAdapter(mAdapter);*/
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getJSON(){
class GetJSON extends AsyncTask<Void,Void,String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
JSON_STRING = s;
showItem();
}
@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequest(Item_Konfigurasi.URL_GET_ALL);
return s;
}
}
GetJSON gj = new GetJSON();
gj.execute();
}
Edit Question : How to make ArrayAdapter for Spinner if i Used ArrayList>? meanwhile i just want 1 of 6 data in array to showing in Spinner (kode/ITEMDATA0)..
Edit : oh yeah i used ArrayList>, it must be different from ArrayList, right?