第一步:创建 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. .NET framework访问Oracle的几种方法

    首先介绍下开发环境:WIn10 64bit+Visual Studio 2015+Oracle10ClientWin32(只是客户端,如果安装整个数据库也是可以的) 目前了解C#中连接Oracle数据 ...

  2. MySQL语法大全_自己整理的学习笔记(MySQL语句 整理二)

    select * from emp; #注释 #--------------------------- #----命令行连接MySql--------- #启动mysql服务器 net start m ...

  3. Springboot Application 集成 OSGI 框架开发

    内容来源:https://www.ibm.com/developerworks/cn/java/j-springboot-application-integrated-osgi-framework-d ...

  4. temp--内蒙农信出差

    ============================2018.09.18~~~20181001================================== -------住宿----黎明花 ...

  5. js实现全屏和缩放

    /** * @description 简单的浏览器检查结果. * `webkit` * webkit版本号,如果浏览器为非webkit内核,此属性为`undefined`. * `chrome` * ...

  6. ArcSDE

    ArcSDE,即数据通路,是ArcGIS的空间数据引擎,它是在关系数据库管理系统(RDBMS)中存储和管理多用户空间数据库的通路.从空间数据管理的角度看,ArcSDE是一个连续的空间数据模型,借助这一 ...

  7. 0x66 Tarjan算法与无向图连通性(1)

    ……是什么? 给定无向连通图G=(V,E)(不一定连通); 割点:若对于x∈V,从图中删去节点x以及所有与x关联的边后,G分裂成两个或两个以上不相连的子图,则称x为G的割点. 桥(割边):若对于e∈E ...

  8. Python学习过程中各个难点---数据类型篇

    ---恢复内容开始--- 当时在学习python的基本数据类型时,对于可变与不可变类型不是了解的很透彻,这篇是回过头来自己的一些理解. 可变的数据类型有列表,不可变的数据类型有字符串,数字和元组   ...

  9. 6-使用requests库封装类处理get/post请求

    1.request安装 1)pip安装,直接pip install requests 2)下载离线包安装,加压后,命令行进入路径,执行python setup.py install 2.创建工程 注意 ...

  10. python基础自学 第五天(附带视频和相关资源)

    数据类型 01.列表 List 是 python 中使用最频繁的数据类型,在其他语言中叫做数组 专门用于存储一串信息 列表用 [ ] 定义,数据之间用 , 分隔 列表的索引从 0 开始 补:索引就是数 ...