2017-04-20 141 views
0
<?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"> 
     <EditText 
      android:id="@+id/et_user_name" 
      android:hint="Enter Username" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

我無法在此活動中找到EditText的資源ID。無法找到Xamarin中的資源ID

using Android.App; 
using Android.OS; 
using MvvmCross.Droid.Views; 

namespace ExpenseApp.Android.Views 
{ 
    [Activity(Label = "View for FirstViewModel")] 
    public class FirstView : MvxActivity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      SetContentView(Resource.Layout.FirstView); 
      EditText username = FindViewById<EditText>(Resource.Id.et_user_name); 
     } 
    } 
} 

我也清理解決方案,並重建解決方案,但仍然無法找到解決方案。

+0

不會吧編譯/運行?什麼是錯誤? –

+0

你有「ViewView」的ViewModel嗎?爲什麼不使用ViewModel將值綁定到視圖?這就是MvvmCross的意圖。 – bslein

+0

我不打包來編譯它。它顯示無法打包找到資源ID。 –

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" // add this line 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<EditText 
      android:id="@+id/et_user_name" 
      android:hint="Enter Username" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      local:MvxBind="Value Property" /> <-- bind your data direct 

    </LinearLayout> 

我不知道爲什麼這個錯誤引發可能是你不需要使用FindViewById方法使用MvxActivity您可以通過我提

希望的方式將數據綁定這項工作

+0

謝謝,它的工作。 –