第一步:创建 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. [原创]networkx 画中文节点

    一直想分享一些自己遇到的坑,但确实很多时候走的太快 很多想做的事情会被快节奏的生活冲淡, 在公司做事反而比学校还自在, 因为是悠闲的实习期... 几点小建议写在前头--xdj: 遇到问题,大多数人首先 ...

  2. 给div"上"滑动条

    最近做项目时修改一个遗留的bug,大概是这样:有一个聊天窗口,用户聊天内容展现在窗口上.其实这个窗口是一个带滑动条的div,随着聊天内容的添加,滑动条也越来越长了,这不是重点,重点是每次刷新窗口时候, ...

  3. xml中CDATA包含问题

    最近对接徐州一家医院,his是东联的,其中有个接口要求传入格式类似于 : <![CDATA[ <Request> <CardNo>000002629518</Car ...

  4. C++标准库第二版笔记 2.1

    C++标准库第二版笔记 2.1 1 Range-Based for 循环 for ( decl : coll ) { statements; } // collaborate 类似C# foreach ...

  5. 深入理解java虚拟机(三)-----类加载机制

    类加载机制jvm把描述类的数据从class文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被jvm直接使用的java类型.在java中,类型的加载.连接和初始化都是在程序运行期间完成的 ...

  6. java构建树形菜单递归工具类

    1.设计菜单实体 import java.util.List; public class Menu { //菜单id private Long id; //父节点id private Long par ...

  7. Eclipse搭建SSH框架(Struts2+Spring+Hibernate)

    见识少的我经过一天多的研究才知道,在MyEclipse中搭好的框架的配置文件和jar包是通用的.接下来——亮剑! 工具:Eclipse+Tomcat+Mysql 一.先在Eclipse中配置好Tomc ...

  8. VC6 LINK : fatal error LNK1168: cannot open Debug/Test.exe for writing

    在使用VC++运行程序时,第一次没有任何问题,但是当再次运行时就会出现:LINK : fatal error LNK1168: cannot open Debug/Test.exe for writi ...

  9. 基于模型的特征选择详解 (Embedded & Wrapper)

    目录 基于模型的特征选择详解 (Embedded & Wrapper) 1. 线性模型和正则化(Embedded方式) 2. 基于树模型的特征选择(Embedded方式) 3. 顶层特征选择算 ...

  10. JAVA数据结构之链表

    JAVA数据结构之链表 什么是链表呢? 链表作为最基本的数据结构之一,定义如下: 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的. 简单来说呢,链 ...