0

So, I create custom spinner base on tutorial from (Android - configure Spinner to use array) and (http://www.katr.com/article_android_spinner01.php)
and her the exxample of my code

      getAkun.getAkunUserKategori(data,tipee, new Akun_Get.dataCallBack() {
        @Override
        public void getData(List<tblAkunDatabase> value) {
            result = value;
            List<spinerAkun> daatspiner;
            daatspiner = new ArrayList<spinerAkun>();
            for(int i = 0;i< result.size();i++)
            {
                daatspiner.add(new spinerAkun(result.get(i).getKdAkun(),result.get(i).getNmAkun()));

                ArrayAdapter<String> adapter = new ArrayAdapter(Edit_Jurnal.this, android.R.layout.simple_dropdown_item_1line, daatspiner);
                spin.setAdapter(adapter);

            }

        }

    });

so, actualy it's working. But the problem is when I try to set a spinner value from database. by using spin.setSelection(daatspiner.indexof("datafromdatabase")) . But it get a error "android.content.res.Resources$NotFoundExceptionn: String resource ID #0xffffffff at .....". So to fix that? Thank You

update

ok, I don't know if this's really solve my problem or not. But my win win solution is create a another array, so I can get the index from tatx array and use the index from taht array to my spinner spin.setSelection(Arrays.asList(array).indexOf("value"))

Jan sebastian
  • 308
  • 1
  • 4
  • 18
  • If I understand your question you want to add database values to the spinner, and then select one of the spinner values ? – Bruno Ferreira Nov 18 '17 at 17:42
  • @BrunoFerreira yes, after I get a pupulate data from database to spinner I want to set the selected value to spinner base on selected data on database – Jan sebastian Nov 18 '17 at 17:45
  • the `daatspiner.indexof("datafromdatabase")` is a number ? – Bruno Ferreira Nov 18 '17 at 17:48
  • @BrunoFerreira yes, try to get an index number of the value using "datafromdatabase" – Jan sebastian Nov 18 '17 at 17:58
  • And if you do this `Integer.parseInt(daatspiner.indexof("datafromdatabase"))` so code will be `spin.setSelection(Integer.parseInt(daatspiner.indexof("datafromdatabase")))` – Bruno Ferreira Nov 18 '17 at 18:08
  • @BrunoFerreira I try already try `spin.setSelection(Integer.parseInt(daatspiner.indexof("dataf‌​romdatabase")))` but I got error message "android.content.res.Resources$NotFoundException: String resource ID #0xffffffff when try to get – Jan sebastian Nov 18 '17 at 18:21
  • probably inside you are adding a new adapter to the spinner every time the for executes, what happens if you execute this `ArrayAdapter adapter = new ArrayAdapter(Edit_Jurnal.this, android.R.layout.simple_dropdown_item_1line, daatspiner); spin.setAdapter(adapter); ` outside the for loop – Bruno Ferreira Nov 18 '17 at 20:50
  • @BrunoFerreira can you explain me more spesificly? – Jan sebastian Nov 20 '17 at 02:50
  • @BrunoFerreira if I try to show daatspiner.indexof("datafromdatabase") in log, it return -1 – Jan sebastian Nov 20 '17 at 03:30

1 Answers1

0

My win win solution is create a another array, so I can get the index from tatx array and use the index from taht array to my spinner spin.setSelection(Arrays.asList(array).indexOf("value"))

Jan sebastian
  • 308
  • 1
  • 4
  • 18