2017-04-20 143 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

谢谢,它的工作。 –