Android spinner, OnItemSelectedListener is not called when selecting the same item?
up vote
0
down vote
favorite
For a particular reason I need my spinner
's OnItemSelectedListener
gets called even when user chooses the same item, but normally it doesn't. So I don't know how it is possible!
Any trick or libraries that can solve my problem?
android spinner
|
show 1 more comment
up vote
0
down vote
favorite
For a particular reason I need my spinner
's OnItemSelectedListener
gets called even when user chooses the same item, but normally it doesn't. So I don't know how it is possible!
Any trick or libraries that can solve my problem?
android spinner
you can useOnItemClickListener
event insteadOnItemSelectedListener
– Farrokh
Nov 10 at 6:05
Sounds likeOnItemClickListener
is not intended to be used with Android'sSpinner
, because when I do it, the app crashes. @Farrokh
– SSP
Nov 10 at 6:09
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
For a particular reason I need my spinner
's OnItemSelectedListener
gets called even when user chooses the same item, but normally it doesn't. So I don't know how it is possible!
Any trick or libraries that can solve my problem?
android spinner
For a particular reason I need my spinner
's OnItemSelectedListener
gets called even when user chooses the same item, but normally it doesn't. So I don't know how it is possible!
Any trick or libraries that can solve my problem?
android spinner
android spinner
asked Nov 10 at 6:03
SSP
518
518
you can useOnItemClickListener
event insteadOnItemSelectedListener
– Farrokh
Nov 10 at 6:05
Sounds likeOnItemClickListener
is not intended to be used with Android'sSpinner
, because when I do it, the app crashes. @Farrokh
– SSP
Nov 10 at 6:09
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30
|
show 1 more comment
you can useOnItemClickListener
event insteadOnItemSelectedListener
– Farrokh
Nov 10 at 6:05
Sounds likeOnItemClickListener
is not intended to be used with Android'sSpinner
, because when I do it, the app crashes. @Farrokh
– SSP
Nov 10 at 6:09
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30
you can use
OnItemClickListener
event instead OnItemSelectedListener
– Farrokh
Nov 10 at 6:05
you can use
OnItemClickListener
event instead OnItemSelectedListener
– Farrokh
Nov 10 at 6:05
Sounds like
OnItemClickListener
is not intended to be used with Android's Spinner
, because when I do it, the app crashes. @Farrokh– SSP
Nov 10 at 6:09
Sounds like
OnItemClickListener
is not intended to be used with Android's Spinner
, because when I do it, the app crashes. @Farrokh– SSP
Nov 10 at 6:09
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
ok
you can use addOnLayoutChangeListener
yourspinner.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
Toast.makeText(context, "item is : " + yourspinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
);
Doesn't help honestly. But it gave me the idea to get theSpinner
popup view somehow thenpopup.addOnLayoutChangeListener
! But how to getSpinner
popup? @Farrokh
– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
add a comment |
up vote
0
down vote
Make sure about the context. you can context as.
this
MainActivity.this
getApplicationContext()
If you are using the spinner in Fragment then you can use context as
getActivity()
String selectedItem;
String data="Australia","Delhi","Agra","Mumbai","America","Tanzania","Arizona";
spinner=(Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
spinner.setPrompt("Select State");
spinner.setAdapter(ad);
String val=spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
String val=spinner.getSelectedItem().toString();
selectedItem=data[i];
Toast.makeText(MainActivity.this, " "+selectedItem, Toast.LENGTH_SHORT).show();
@Override
public void onNothingSelected(AdapterView<?> adapterView)
);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
ok
you can use addOnLayoutChangeListener
yourspinner.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
Toast.makeText(context, "item is : " + yourspinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
);
Doesn't help honestly. But it gave me the idea to get theSpinner
popup view somehow thenpopup.addOnLayoutChangeListener
! But how to getSpinner
popup? @Farrokh
– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
add a comment |
up vote
0
down vote
accepted
ok
you can use addOnLayoutChangeListener
yourspinner.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
Toast.makeText(context, "item is : " + yourspinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
);
Doesn't help honestly. But it gave me the idea to get theSpinner
popup view somehow thenpopup.addOnLayoutChangeListener
! But how to getSpinner
popup? @Farrokh
– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
ok
you can use addOnLayoutChangeListener
yourspinner.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
Toast.makeText(context, "item is : " + yourspinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
);
ok
you can use addOnLayoutChangeListener
yourspinner.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
Toast.makeText(context, "item is : " + yourspinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
);
answered Nov 10 at 6:29
Farrokh
1,0731615
1,0731615
Doesn't help honestly. But it gave me the idea to get theSpinner
popup view somehow thenpopup.addOnLayoutChangeListener
! But how to getSpinner
popup? @Farrokh
– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
add a comment |
Doesn't help honestly. But it gave me the idea to get theSpinner
popup view somehow thenpopup.addOnLayoutChangeListener
! But how to getSpinner
popup? @Farrokh
– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
Doesn't help honestly. But it gave me the idea to get the
Spinner
popup view somehow then popup.addOnLayoutChangeListener
! But how to get Spinner
popup? @Farrokh– SSP
Nov 10 at 6:38
Doesn't help honestly. But it gave me the idea to get the
Spinner
popup view somehow then popup.addOnLayoutChangeListener
! But how to get Spinner
popup? @Farrokh– SSP
Nov 10 at 6:38
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
i tried this code and do what you need, every time spinner layout changes, a toast appear on screen, it include selecting new item or clicking same item, what do you need exactly?
– Farrokh
Nov 10 at 6:41
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
I'm sorry. You are right! It is exactly what I want :)
– SSP
Nov 10 at 6:45
add a comment |
up vote
0
down vote
Make sure about the context. you can context as.
this
MainActivity.this
getApplicationContext()
If you are using the spinner in Fragment then you can use context as
getActivity()
String selectedItem;
String data="Australia","Delhi","Agra","Mumbai","America","Tanzania","Arizona";
spinner=(Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
spinner.setPrompt("Select State");
spinner.setAdapter(ad);
String val=spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
String val=spinner.getSelectedItem().toString();
selectedItem=data[i];
Toast.makeText(MainActivity.this, " "+selectedItem, Toast.LENGTH_SHORT).show();
@Override
public void onNothingSelected(AdapterView<?> adapterView)
);
add a comment |
up vote
0
down vote
Make sure about the context. you can context as.
this
MainActivity.this
getApplicationContext()
If you are using the spinner in Fragment then you can use context as
getActivity()
String selectedItem;
String data="Australia","Delhi","Agra","Mumbai","America","Tanzania","Arizona";
spinner=(Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
spinner.setPrompt("Select State");
spinner.setAdapter(ad);
String val=spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
String val=spinner.getSelectedItem().toString();
selectedItem=data[i];
Toast.makeText(MainActivity.this, " "+selectedItem, Toast.LENGTH_SHORT).show();
@Override
public void onNothingSelected(AdapterView<?> adapterView)
);
add a comment |
up vote
0
down vote
up vote
0
down vote
Make sure about the context. you can context as.
this
MainActivity.this
getApplicationContext()
If you are using the spinner in Fragment then you can use context as
getActivity()
String selectedItem;
String data="Australia","Delhi","Agra","Mumbai","America","Tanzania","Arizona";
spinner=(Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
spinner.setPrompt("Select State");
spinner.setAdapter(ad);
String val=spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
String val=spinner.getSelectedItem().toString();
selectedItem=data[i];
Toast.makeText(MainActivity.this, " "+selectedItem, Toast.LENGTH_SHORT).show();
@Override
public void onNothingSelected(AdapterView<?> adapterView)
);
Make sure about the context. you can context as.
this
MainActivity.this
getApplicationContext()
If you are using the spinner in Fragment then you can use context as
getActivity()
String selectedItem;
String data="Australia","Delhi","Agra","Mumbai","America","Tanzania","Arizona";
spinner=(Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
spinner.setPrompt("Select State");
spinner.setAdapter(ad);
String val=spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
String val=spinner.getSelectedItem().toString();
selectedItem=data[i];
Toast.makeText(MainActivity.this, " "+selectedItem, Toast.LENGTH_SHORT).show();
@Override
public void onNothingSelected(AdapterView<?> adapterView)
);
edited Nov 10 at 12:02
Rahul Sharma
2,0041415
2,0041415
answered Nov 10 at 6:54
Black4Guy
65
65
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236422%2fandroid-spinner-onitemselectedlistener-is-not-called-when-selecting-the-same-it%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
you can use
OnItemClickListener
event insteadOnItemSelectedListener
– Farrokh
Nov 10 at 6:05
Sounds like
OnItemClickListener
is not intended to be used with Android'sSpinner
, because when I do it, the app crashes. @Farrokh– SSP
Nov 10 at 6:09
do u have more than a spinner ???
– hamid keyhani
Nov 10 at 6:16
Yeah, I've got other widgets too. But I don't think it's a matter of their presence. Look, there is no issue to get solved. It's a problem that needs a solution. @hamidkeyhani
– SSP
Nov 10 at 6:27
i'm so sorry for my wrong answer, but you can try my new answer posted below
– Farrokh
Nov 10 at 6:30