Android 带有Xamarin的抽屉布局中的ImageView和TextView

Android 带有Xamarin的抽屉布局中的ImageView和TextView,android,android-layout,xamarin.android,xamarin,navigation-drawer,Android,Android Layout,Xamarin.android,Xamarin,Navigation Drawer,在过去的几天里,我一直在尝试将数据绑定到抽屉布局,但运气不佳。我认为我的问题是数据的绑定,并确保在正确的位置有正确的参数。代码如下。出于此代码的目的,我有一个从Resources.array.NavigationItems加载的项数组。一旦我在一个字符串数组中有了它,我就遍历这个列表,创建一个字典,其中有一个条目,它是要显示的文本,还有一个图像,它是我要显示的图像。此时,图像只是从我的资源的Drawable加载的。然后创建两个数组。这两个数组应该映射到必要的from(javalist中的数据)和

在过去的几天里,我一直在尝试将数据绑定到抽屉布局,但运气不佳。我认为我的问题是数据的绑定,并确保在正确的位置有正确的参数。代码如下。出于此代码的目的,我有一个从Resources.array.NavigationItems加载的项数组。一旦我在一个字符串数组中有了它,我就遍历这个列表,创建一个字典,其中有一个条目,它是要显示的文本,还有一个图像,它是我要显示的图像。此时,图像只是从我的资源的Drawable加载的。然后创建两个数组。这两个数组应该映射到必要的from(javalist中的数据)和to(要显示的控件的id。当我运行下面的代码时,我会看到代码下面显示的错误。我假设我的字典定义有问题。我们非常感谢您的建议。老实说,我不确定我是否使用正确的对象正确创建了字典或列表;我从java翻译的技能net在这方面可能还缺乏

_navigationItems = Resources.GetStringArray(Resource.Array.NavigationItems);

var mList = new List<IDictionary<string, object>>(); 
for(int i=0;i<_navigationItems.Length;i++){
    var hm = new Dictionary<String,Object>();
    hm.Add("item", _navigationItems[i]);
    hm.Add("image", Resource.Drawable.aniswath);
    mList.Add(hm);
}
var fromH = new string[]{ "item", "image" };
var toH = new int[] { Resource.Id.title, Resource.Id.icon };

_drawerList.Adapter = new SimpleAdapter (this, mList, 
Resource.Layout.custom_drawer_item, fromH, toH);

你最好自己制作
适配器
而不是使用
SimpleAdapter
。这样可以省去你在
Java.Lang.Object
中包装东西的麻烦。谢谢Cheesebaron。我收到了别人的代码。我永远都不明白为什么它不能正常工作。根据你的建议,我在一个fe中重新编写了这个今天早上我只花了w分钟,它就成功了。谢谢你给我的建议,让我走上正确的道路。:-)也谢谢你对那些使我走上正确道路的建议所做的更改/编辑。:-)
   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="25dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:src="@drawable/aniswath" />
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/icon"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textStyle="bold"
        android:gravity="center_vertical"
        android:paddingRight="40dp" />
</LinearLayout>
04-11 21:40:50.022: E/AndroidRuntime(2515): java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map
04-11 21:40:50.022: E/AndroidRuntime(2515): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:147)
04-11 21:40:50.022: E/AndroidRuntime(2515): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)