1

I use Spinner in Dialog Mode. I set SimpleCursorAdapter for the Spinner with setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); That works fine.

Now instead of simple_spinner_dropdown_item I'm trying to pass my custom layout it does work well too.

But there is a but... it does not have radio button that original simple_spinner_dropdown_item does. Is it possible to add radio button inside of my custom spinner_dropdown_item that would be selected when spinner dialog is shown?

Ben
  • 175
  • 1
  • 2
  • 12

2 Answers2

0

yes its possible but you have to define a another class for spinner.Just look at this

you have one more option to get your requirement. that is Alert dialog

just check out this Alert Dialog Window with radio buttons in Android and How to create custom and drop down type dialog and Dialog in android

Community
  • 1
  • 1
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
0

Well I have found solution. ListView (what is inside of the spinners dialog) will check if your View is Checkable and call setChecked. Since android.R.layout.simple_spinner_dropdown_item is checkable it works. So for my custom List item i have created LinearLayout that implements Checkable

public class CheckableLinearLayout extends LinearLayout implements Checkable
{
private boolean _isChecked = false;

public CheckableLinearLayout(Context context)
    {
    super(context);
    }

public CheckableLinearLayout(Context context, AttributeSet attrs)
    {
    super(context, attrs);
    }

@Override
public void setChecked(boolean checked)
    {
    _isChecked = checked;

    for (int i = 0; i < getChildCount(); i++)
        {
        View child = getChildAt(i);
        if (child instanceof Checkable)
            {
            ((Checkable) child).setChecked(_isChecked);
            }
        }
    }

@Override
public boolean isChecked()
    {
    return _isChecked;
    }

@Override
public void toggle()
    {
    _isChecked = !_isChecked;
    }

}

So ListView calls setChecked and I propagate that down to children views and my CheckBox / RadioButton will get checked / unchecked correctly.

Ben
  • 175
  • 1
  • 2
  • 12