android - Can't use Spinner.setSelection from Database -


i make application can input data spinner database when user open activity spinner retrieve data db , if user change value of spinner, refresh spinner (in case if user click edit button, data not match database) how can fix this?

this code :

    protected void oncreate(@nullable bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.editfpp);             getalamatbill(id);     }      @override         protected void onresume() {             super.onresume();       spinnerprovinsibill.setonitemselectedlistener(new adapterview.onitemselectedlistener() {                 @override                 public void onitemselected(adapterview<?> parent, view view, int position, long id) {                     string kodeprovinsi = helper.getrefprovinsi(spinnerprovinsibill.getselecteditem().tostring());                     ambilkabupaten(kodeprovinsi, spinnerkabupatenbill);                 }                  @override                 public void onnothingselected(adapterview<?> parent) {                  }             });              spinnerkabupatenbill.setonitemselectedlistener(new adapterview.onitemselectedlistener() {                 @override                 public void onitemselected(adapterview<?> parent, view view, int position, long id) {                     string kodekabupaten = helper.getrefkabupaten(spinnerkabupatenbill.getselecteditem().tostring());                     ambilkecamatan(kodekabupaten, spinnerkecamatanbill);                 }                  @override                 public void onnothingselected(adapterview<?> parent) {                  }             });      }          private void ambilkecamatan(string kodekabupaten, spinner spinnerkecamatanbill) {             list<string> data = helper.getkecamatan(kodekabupaten);             arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.spinner_background, data);             adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             spinnerkecamatanbill.setadapter(adapter);         }          private void ambilkabupaten(string kodeprovinsibill, spinner spinnerkabupatenbill) {             list<string> data = helper.getkabupaten(kodeprovinsibill);             arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.spinner_background, data);             adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             spinnerkabupatenbill.setadapter(adapter);         }     private void ambilprovinsipilihan(spinner spinner, string namaprovinsi, string kabupaten, string kecamatan, string kelurahan){         list<string> data = helper.getprovinsi();         arrayadapter<string> dataadapter = new arrayadapter<string>(this, r.layout.spinner_background, data);         dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);         spinner.setadapter(dataadapter);         int posisi = dataadapter.getposition(namaprovinsi);         spinner.setselection(posisi);         system.out.println("hasil = " + helper.getrefkabupaten(kabupaten) + " " + helper.getrefkecamatan(kecamatan));      }  private void getalamatbill(string id) {         try {             system.out.println("persiapan data: " + id);             jsonarray array = new jsonarray(helper.getalamatship(id));             jsonobject object = array.getjsonobject(0);             string alamat = object.getstring("alamat");             string kdpos = object.getstring("kdpos");             string kelurahan = object.getstring("kelurahan");             string kecamatan = object.getstring("kecamatan");             string kabupaten = object.getstring("kabupaten");             string provinsi = object.getstring("provinsi");             string kota = object.getstring("kota");             ambilprovinsipilihanship(spinnerprovinsiship, provinsi, kabupaten, kecamatan, kelurahan);             ambilkotapilihan(spinnerkotaship, kota);             edalamatship.settext(alamat);             edkodeposship.settext(kdpos);         } catch (jsonexception e) {             e.printstacktrace();         }     } 

thanks in advance


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -