0

Is there a way to get the item position on Spinner Object by only focusing and not by OnItemSelected in Android?

Cause i need to add/increment an item when everytime the last item of spinner is focus..

Jun M.
  • 17
  • 2

1 Answers1

2

Try this.It is working fine.

@Override
 public void onItemSelected(final AdapterView<?> parent, View view,
        final int position, long id) {

    parent.post(new Runnable() {
        @Override
        public void run() {
            spinner.requestFocusFromTouch();
            long pos = spinner.getItemIdAtPosition(position+1);
            Toast.makeText(getApplicationContext(), "Position : " +pos, Toast.LENGTH_SHORT).show();

        }
    });
}
Naveen
  • 814
  • 2
  • 9
  • 22
  • thanks naveen, but what do you mean by sp2? i got an error. – Jun M. Oct 30 '15 at 06:37
  • sp2 means Spinner.I edited the code now.Please check it once.Can you voteup my answer ? @Jun M. – Naveen Oct 30 '15 at 06:39
  • @JunM. I was looking for such question. How you add/increment an item when everytime the last item of spinner is focus ? – Jaimin Modi Oct 30 '15 at 06:51
  • Check this link http://stackoverflow.com/questions/2160518/how-to-add-items-to-the-spinner-dynamically-in-android @JaiminModi – Naveen Oct 30 '15 at 07:02
  • @Naveen my question is how to find the item position by focusing? not by onItemSelected.. btw Thanks – Jun M. Oct 30 '15 at 07:17
  • @JaiminModi im stil stock with this, let me know if you already solve this. – Jun M. Oct 30 '15 at 07:17