2016-04-28 15 views
0

Ich habe Floating-Button in den FundamentalView.axmlTextview klickbaren in MVVMCross

<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 dem FundamentalView.cs, ich habe Ereignis klicken, das ein Fragment aus dem unteren Teil der Ansicht löst mit Optionen, die (das Hinzufügen eines neuen Person und neue Berechnungen).

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> 

Meine Frage ist, wie Textview anklickbar und wissen zu machen, die in mvvmcross geklickt Textview?

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 })); 
     } 
    } 
} 

Antwort

3

können Sie binden wie als Schaltfläche klicken Textview klicken:

<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" /> 

Für die zweite tex tview binden Sie es an einen anderen Befehl. Auf diese Weise erfahren Sie, wenn Sie den entsprechenden Befehl aufrufen, welche Textansicht sie ausgelöst hat.

+0

Danke Giorgi, woher weiß ich, welche Textansicht angeklickt wird? – hotspring

+1

@hotspring: Siehe meine aktualisierte Antwort. – Giorgi

+0

Großartig! Dann muss ich 'CardDialogViewModel' für das Fragment haben, habe ich recht? – hotspring