casillas
casillas

Reputation: 16793

disable selection of the spinner

How could I disable selection of the spinner

<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:textColor="@color/primary_text"   
  local:MvxItemTemplate="@layout/spinner_template"
  local:MvxBind="ItemsSource StudentList; ItemSelected StudentType" />

Upvotes: 0

Views: 653

Answers (2)

Cheesebaron
Cheesebaron

Reputation: 24460

You can bind directly to the Enabled property on the Spinner:

local:MvxBind="ItemsSource StudentList; ItemSelected StudentType; Enabled IsEnabled"

The same goes for any other public property. Although most of them will be OneWay bindings, which shouldn't matter in this case though.

You ViewModel property would look like any other property:

private bool _isEnabled;
public bool IsEnabled
{
    get { return _isEnabled; }
    set { SetProperty(ref _isEnabled, value); }
}

Then when you need to enable/disable the control:

IsEnabled = true;

Upvotes: 1

RestingRobot
RestingRobot

Reputation: 2978

Try this:

<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
  android:id=@+id/spinner1
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:textColor="@color/primary_text"   
  android:enabled="false"
  android:clickable="false"
  local:MvxItemTemplate="@layout/spinner_template"
  local:MvxBind="ItemsSource StudentList; ItemSelected StudentType" />

To enable, in your activity/fragment try this.

  MvxAppCompatSpinner spinner1 = (MvxAppCompatSpinner)findViewById(R.id.spinner1);
  spinner1.setEnabled(true);
  spinner1.setClickable(true);

Upvotes: 1

Related Questions