• VS 2019开发APP(三)listview的应用


    using System.Collections.Generic;

    using Android.App;
    using Android.OS;
    using Android.Support.V7.App;
    using Android.Runtime;
    using Android.Widget;

    namespace App3
    {
      [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
      public class MainActivity : AppCompatActivity
      {

        SimpleAdapter content;//定义适配器
        IList<IDictionary<string, object>> data;//定义数据

        protected override void OnCreate(Bundle savedInstanceState)
        {
          base.OnCreate(savedInstanceState);
          Xamarin.Essentials.Platform.Init(this, savedInstanceState);
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.activity_main);

          ListView list = FindViewById<ListView>(Resource.Id.listView1);//绑定ListView

          data = new List<IDictionary<string, object>>();//初始化数据

          /*添加数据内容*/
          for (int i = 0; i < 20; i++)
          {
            JavaDictionary<string, object> achievement = new JavaDictionary<string, object>();
            achievement.Add("Name", i.ToString());
            data.Add(achievement);
          }

          content = new SimpleAdapter(this, data, Android.Resource.Layout.SimpleListItem2, new string[] { "Name" }, new int[] { Android.Resource.Id.Text1 });//创建数据适配器
          list.Adapter = content;//将适配器数据添加到ListView
        }
      }
    }

  • 相关阅读:
    Shell脚本中循环语句for,while,until用法
    国内yum源的安装(163,阿里云,epel)
    express高效入门教程(4)
    express高效入门教程(3)
    express高效入门教程(2)
    express高效入门教程(1)
    dart快速入门教程 (8)
    dart快速入门教程 (7.4)
    dart快速入门教程 (7.3)
    dart快速入门教程 (7.2)
  • 原文地址:https://www.cnblogs.com/sunsuoli/p/12201687.html
Copyright © 2020-2023  润新知