Reputation: 16793
I have floating button in the FundamentalView.axml
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="22dp"
android:paddingRight="22dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
<ImageButton
android:id="@+id/addButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@drawable/ic_add_white_24dp" />
</FrameLayout>
In the FundamentalView.cs, I have click event which triggers a fragment from the bottom of the view with having options (adding a new person and new calculations).
var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton);
addButton.Click += OnAddButtonClick;
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");
}
CardDialogView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_computer"
android:textColor="@color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="@color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
My question is how to make TextView clickable and know which textview clicked in mvvmcross?
CardDialogView.cs
public class CardDialogView : MvxDialogFragment<CardDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
.....
return dialog;
}
}
CardDialogViewModel.cs
public class CardDialogViewModel : MvxViewModel
{
public ICommand NewCalculationCommand
{
get
{
// it does not come here!
return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now }));
}
}
}
Upvotes: 0
Views: 805
Reputation: 30873
You can bind textview click just like as button click:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_computer"
android:textColor="@color/primary_text"
android:textSize="16sp"
local:MvxBind="Click NewCalculationCommand"
android:text="New Calculation" />
For the second textview bind it to another command. This way when the corresponding command is invoked you will know which textview triggered it.
Upvotes: 2