第一步:创建 layout1.axml 来展示列表详细内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<ImageView
android:id="@+id/img"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_marginLeft="20dp" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:textColor="#000000"/>
</LinearLayout>

第二步:在 Main.axml 添加 ListView

<?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">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ListView
android:id="@+id/left_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:text="DrawerLayout" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>

第三步:创建 SimpleAdapter 数据适配器

using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
using System;
using Android.Runtime; namespace SimpleAdapterDemo
{
[Activity(Label = "SimpleAdapterDemo", MainLauncher = true)]
public class MainActivity : Activity
{
private ListView listview_leftMenu;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main); listview_leftMenu = FindViewById<ListView>(Resource.Id.left_menu); //创建数据适配器
SimpleAdapter content = new SimpleAdapter(
this,
GetData(),
Resource.Layout.layout1,
new string[] { "img", "name" },
new int[] { Resource.Id.img, Resource.Id.name });
//把数据绑定到list_member 这个listview上 listview_leftMenu.Adapter = content; listview_leftMenu.ItemClick += (s, e) =>
{
Listview_leftMenu_ItemClick(e.Position);
};
} private void Listview_leftMenu_ItemClick(int position)
{
Toast.MakeText(this, list[position]["name"].ToString(), ToastLength.Short).Show();
} IList<IDictionary<string, Object>> list = new JavaList<IDictionary<string, Object>>();
private IList<IDictionary<string, Object>> GetData()
{
//map.put(参数名字,参数值) JavaDictionary<string, Object> map; map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息1");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息2");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息3");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息4");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息5");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息6");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息7");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息8");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息1");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息2");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息3");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息4");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息5");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息6");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息7");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); map = new JavaDictionary<string, Object>();
map.Add("name", "我的信息8");
map.Add("img", Resource.Drawable.icon_myinfo);
list.Add(map); return list;
}
}
}

效果:

最后附上源码地址:

  链接: https://pan.baidu.com/s/1hs6NIEmqVXOq_bI9fjkl0Q

  提取码: 67nk

Xamarin.Android 使用 SimpleAdapter 打造 ListView 万能适配器的更多相关文章

  1. android listview万能适配器

    参考    Android 快速开发系列 打造万能的ListView GridView 适配器 Hongyang public class CommonViewHolder { private Con ...

  2. 打造android偷懒神器———RecyclerView的万能适配器

    转载请注明出处谢谢:http://www.cnblogs.com/liushilin/p/5720926.html 很不好意思让大家久等了,本来昨天就应该写这个的,无奈公司昨天任务比较紧,所以没能按时 ...

  3. [置顶] Xamarin android 调用Web Api(ListView使用远程数据)

    xamarin android如何调用sqlserver 数据库呢(或者其他的),很多新手都会有这个疑问.xamarin android调用远程数据主要有两种方式: 在Android中保存数据或调用数 ...

  4. Xamarin.Android 入门之:Listview和adapter

    一.引言 不管开发什么软件,列表的使用是必不可少的,而本章我们将学习如何使用Xamarin去实现它,以及如何使用自定义适配器.关于xamarin中listview的基础和适配器可以查看官网https: ...

  5. 打造android偷懒神器———ListView的万能适配器

    如果你去做任何一个项目,我相信你都会跟我有一样的经历,最最普遍的就是列表显示ListView,当然,写N个自定义的适配器也是情理之中.虽说程序员本身就是搬砖,做这些枯燥无味的重复的事情也是理所当然,但 ...

  6. Android 快速开发系列 打造万能的ListView GridView 适配器

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38902805 ,本文出自[张鸿洋的博客] 1.概述 相信做Android开发的写 ...

  7. Android之ListView性能优化——一行代码绑定数据——万能适配器

    如下图,加入现在有一个这样的需求图,你会怎么做?作为一个初学者,之前我都是直接用SimpleAdapter结合一个Item的布局来实现的,感觉这样实现起来很方便(基本上一行代码就可以实现),而且也没有 ...

  8. 安卓开发笔记——打造万能适配器(Adapter)

    为什么要打造万能适配器? 在安卓开发中,用到ListView和GridView的地方实在是太多了,系统默认给我们提供的适配器(ArrayAdapter,SimpleAdapter)经常不能满足我们的需 ...

  9. Android万能适配器Adapter-android学习之旅(74)

    万能适配器的代码的github地址是https://github.com/fengsehng/CommonAdapter 万能适配器的代码的github地址是https://github.com/fe ...

随机推荐

  1. RT-thread-------------------信号量

    信号量:用于解决线程间同步问题的内核对象,线程可以获取或释放它,从而达到同步或互斥的目的.(互斥量只能由持有线程释放,而信号量则可以由任何线程释放) 在rtt中,信号量分为计数型信号量和二值信号量(作 ...

  2. 关于webpack使用的一些问题

    1.镜像安装 npm安装webpack慢的爆炸,如果不能FQ,试下下面的国内良心镜像,浑身都舒爽了. npm config set registry https://registry.npm.taob ...

  3. [入门]在Mac OS X下使用和配置Android Studio

    Android Studio可谓是安卓开发的XCode,流畅的速度+顺眼的UI足以秒杀Eclipse.在Mac OS X可以通过如下的途径获得Android Studio  最新版本的Android ...

  4. IOS11导航栏自定义返回按钮被遮挡

    将file作为请求体传入到服务端. { WaitForSingleObject(handle, INFINITE); printf(" -- by MoreWindows( http://b ...

  5. 一些你不知道的PHP高级语法汇总

    一.执行系统外部命令 system() 输出并返回最后一行shell结果. exec() 不输出结果,返回最后一行shell结果,所有结果可以保存到一个返回的数组里面. passthru() 只调用命 ...

  6. 计蒜客 2019 蓝桥杯省赛 B 组模拟赛(三)数字拆分

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> us ...

  7. ubuntu 安装vue+element

    1.安装npm sudo apt install npm 检测安装npm -v 因为npm安装软件慢,可设置淘宝镜像 npm config set registry https://registry. ...

  8. 微信小程序的自定义插件

    第一步,创建一个页面和普通页面一样 第二不,在这个页面上进行对json配置, "component":true 第三不在需要插入的页面中进行设置 插入标签 <dialog i ...

  9. JAVA Bean和XML之间的相互转换 - XStream简单入门

    JAVA Bean和XML之间的相互转换 - XStream简单入门 背景介绍 XStream的简介 注解简介 应用实例 背景介绍 我们在工作中经常 遇到文件解析为数据或者数据转化为xml文件的情况, ...

  10. HDU 6382 odds (暴力 + 剪枝优化)

    odds Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Subm ...