michaelprimez / searchablespinner

Searchable Spinner
Apache License 2.0
314 stars 102 forks source link

How to get Id of Selected item #45

Open MustafaAndroid opened 5 years ago

MustafaAndroid commented 5 years ago

Hi Everyone. Please guide me to get the ID of particular Id of Selected Item From Spinner I'm getting selected position of selected item from list not id please resolve my problem From this

I'm doing like this

mSearchableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(View view, int position, long id) {

            try {
             String  ctry_ID = askModelList.get(0).getCountryModelList().get(position).getId();
                Log.d("ID", "onItemSelected: "+ctry_ID);
            }catch (Exception e) {
            }

        }

        @Override
        public void onNothingSelected() {

        }
    });
MustafaAndroid commented 5 years ago

I Solve the Problem :100: just getID From ModelClass :1st_place_medal: @Override public String getItem(int position) { if (mStrings != null && position > 0) return mStrings.get(position - 1).getId(); else return null; }