Xamarin SimplerCursorAdapter 适配器(三)

news/2024/7/5 2:33:20

        SimplerCursorAdapter的使用步骤:
            1、根据需要定义ListView每行所实现的布局。
            2、实现数据表的查询操作,获取ICursor对象。
            3、根据SimplerCursorAdapter对象。
            4、将ListView绑定到SimplerCursorAdapter上。

 

信息列表的布局:Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:text="ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtID" />
    <TextView
        android:text="NAME"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtName" />
    <TextView
        android:text="TEL"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtTel" />
</LinearLayout>

 

 

逻辑代码:MainActivity.cs

 

using System;

using Android.App;

using Android.Content;

using Android.Runtime;

using Android.Views;

using Android.Widget;

using Android.OS;

using Android.Database.Sqlite;

using Android.Database;

namespace App1

{    

  [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]    

  public class MainActivity : ListActivity   

   {        

       int count = 1;

            ICursor cursor = null;

          //SimplerCursorAdapter的使用步骤:

                 1、根据需要定义ListView每行所实现的布局。

                 2、实现数据表的查询操作,获取ICursor对象。

                 3、根据SimplerCursorAdapter对象。

                 4、将ListView绑定到SimplerCursorAdapter上。

        protected override void OnCreate(Bundle bundle)

        {

            base.OnCreate(bundle);

            LocalSqliteHelper sqlLocalSqliteHelper = new LocalSqliteHelper(this);

            cursor=sqlLocalSqliteHelper.WritableDatabase.RawQuery("select _id,name,tel from LinkManInfo",null);

            StartManagingCursor(cursor);

            this.ListAdapter=new SimpleCursorAdapter(this,Resource.Layout.Main,cursor,new string[] { "_id","name","tel" },new int[] { Resource.Id.txtID,Resource.Id.txtName,Resource.Id.txtTel });

            // Set our view from the "main" layout resource  

            //SetContentView(Resource.Layout.Main);  

            //选项单击事件

            this.ListView.ItemClick += (sender, e) =>

            {

                cursor.MoveToPosition(e.Position);

                string[] values = { cursor.GetString(1), cursor.GetString(2) };

                Intent intent = new Intent(this, typeof(ShowLinkMan));

                intent.PutExtra("linkMan", values);

                StartActivity(intent);

            };

        }

        protected override void OnDestroy()

        {

            base.OnDestroy();

            StopManagingCursor(cursor);

            cursor.Close();

        }

    }

}

 

 

 

接收信息的页面布局:ShowLinkMan.axml

 

<?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">
    <TextView
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textName" />
    <TextView
        android:text="TEL"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textTel" />
</LinearLayout>

 

代码逻辑:ShowLinkMan.cs

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Android.App;

using Android.Content;

using Android.OS;

using Android.Runtime;

using Android.Views;

using Android.Widget;

namespace App1

{   

  [Activity(Label = "ShowLinkMan")]

    public class ShowLinkMan : Activity

    {

        protected override void OnCreate(Bundle savedInstanceState)

        {

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ShowLinkMan);

            // Create your application here

            string[] values=Intent.GetStringArrayExtra("linkMan");

            FindViewById<TextView>(Resource.Id.textName).Text = "姓名:" + values[0];

            FindViewById<TextView>(Resource.Id.textTel).Text = "电话:" + values[1];

        }

    }

}

 

转载于:https://www.cnblogs.com/bjxingch/articles/5496316.html


http://lihuaxi.xjx100.cn/news/244529.html

相关文章

Spark shuffle调优

Spark shuffle是什么Shuffle在Spark中即是把父RDD中的KV对按照Key重新分区&#xff0c;从而得到一个新的RDD。也就是说原本同属于父RDD同一个分区的数据需要进入到子RDD的不同的分区。现在的spark版本默认使用的是sortshuffle;shuffle在哪里产生shuffle在spark的算子中产生,也就…

在SpringBoot项目中使用redis简单用法(一)

基本准备 首先肯定是需要将Redis的包和Redis链接配置好 这里以maven作为项目构建工具&#xff0c;所以直接在POM文件中引入的Redis依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-r…

一个经典例子让你彻彻底底理解java回调机制

以前不理解什么叫回调&#xff0c;天天听人家说加一个回调方法啥的&#xff0c;心里想我草&#xff0c;什么叫回调方法啊&#xff1f;然后自己就在网上找啊找啊找&#xff0c;找了很多也不是很明白&#xff0c;现在知道了&#xff0c;所谓回调&#xff1a;就是A类中调用B类中的…

微信公众号开发(一)

1.登录开发公众平台 https://mp.weixin.qq.com/ 2.注册填好相关信息登录后 3.设置域名 首先介绍一款在线调试工具https://natapp.cn 注册登录后先购买vip隧道&#xff0c;然后购买二级域名 购买域名 然后下载客户端&#xff0c;使用教程参考https://natapp.cn/article/nata…

Add Digits

题干就是给一个非负整数&#xff0c;把各位数加起来&#xff0c;若超过一位&#xff0c;则继续把各位加起来&#xff0c;直到和是一位数。 example&#xff1a; 39->12->3 坦白说我是看了第三个提示意识到的&#xff0c;所以说要找规律&#xff0c;先要暴力列举。 int ad…

EXTJS之Ext.util.Observable自定义事件

暂时还不会用Ext.mixin.Observable&#xff0c; 催悲的测试了近两个小时。这TMD的语法差距也太大了啊。。 在新版EXTJS里&#xff0c;已去除了addEvents。 弄个出来&#xff0c;大概知道下吧。 ?123456789101112131415161718192021222324252627282930313233343536373839404142…

实例规格 ECS (共享计算型)和 (通用型-原独享)性能上有什么区别? ...

实例规格 ECS (共享计算型)和 (通用型-原独享)性能上有什么区别? 实例规格 共享计算型 和 通用型(原独享), 如果同样是2核4G 或者4核8G ; 性能上有什么差异/差距大吗? 内存型比通用性性能好些&#xff0c;而且CPU和内存配比&#xff1a; 通用型为1&#xff1a;2&…

SpringBoot实现微信点餐

项目介绍 采用前后端分离的方式&#xff0c;前端采用Vue.js&#xff0c;后端采用SpringBoot进行开发