Search code examples
androidspinnerandroid-spinner

How to set value of custom spinner android


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"))


Solution

  • 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"))