krishna krishna - 18 days ago 5
Android Question

problems in android spinner

I want to display messages based on selection of value from spinner.
so i used folowing code.

sp=(Spinner)findViewById(R.id.spinner1);
String ar[]={"hello","abc"};
ArrayAdapter<String> adapt=new ArrayAdapter<String>(SpinnerEampleActivity.this, android.R.layout.simple_spinner_dropdown_item,ar);
sp.setAdapter(adapt);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3)
{
if(arg2==0)
{
AlertDialog.Builder alert=new AlertDialog.Builder(SpinnerEampleActivity.this);
alert.setMessage("hello");
alert.show();
}
else
{
AlertDialog.Builder alert=new AlertDialog.Builder(SpinnerEampleActivity.this);
alert.setMessage("abc");
alert.show();
}

}


but if i select the already selected value from spinner i am not getting any message.
could any help me to solve the problem.
Thanks in advance.

Answer

When you clicks again the currently selected item, then it can not fire any event. So you can not catch setOnItemSelectedListener for spinner to respond.

You need to create your custom spinner adapter to handle the click for the already selected item.