How to Bind Android TextView to Click event with MvvmCross
Asked Answered
Q

3

5

Is it possible to Bind Android TextView to Click event with MvvmCross? Or as alternative make a button which looks like TextView?

Quid answered 11/10, 2013 at 5:22 Comment(0)
Q
10

It is turned out that TextView can be bound same way as Button

local:MvxBind="Click DoCommand"
Quid answered 11/10, 2013 at 5:38 Comment(2)
@AlexPetrenko: in your fragment var set = this.CreateBindingSet<YourFragment, YourViewModel> (); set.Bind (_textView).For (p => p.Click).To (vm => vm.YourCommand); set.Apply ();Aeronautics
it says click can only be used on left hand sideSurvival
B
2

You can bind a text view like this.

           <TextView  android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                local:MvxBind="Click DoThisCommand" />

height and width you can manage according to your convinience. Hope this will help you.

Bello answered 21/1, 2015 at 13:14 Comment(0)
M
2

As the OP may be interested in methods to achieve click binding from code-behind as opposed to xml I have provided the following for guidance:

using MvvmCross.Platforms.Android.Binding;

var set = this.CreateBindingSet<theActivity,theViewModel>();
imageView1.For(x=> x.BindClick()).To(vm=>vm.imageViewClickCmd);
set.Apply()

The MvvmCross.Platforms.Android.Binding namespace provides the BindClick() extension method. Similar methods can be found for alternative events at the following links https://www.mvvmcross.com/documentation/fundamentals/data-binding#built-in-bindings

Alternatively you can use

    imageView1.For("Click").To(vm=>vm.imageViewClickCmd);
Mattox answered 3/9, 2018 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.