不管开发什么软件,列表的使用是必不可少的,而本章我们将学习如何使用Xamarin去实现它,以及如何使用自定义适配器。关于xamarin中listview的基础和适配器可以查看官网https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/ 本章主要介绍如果在listview一项中显示多条数据。

二、准备工作

1.创建一个Android项目取名为MyListview

Xamarin.Android 入门之:Listview和adapter

2.新建2个视图文件

Xamarin.Android 入门之:Listview和adapter

3.下面编辑我们的试图:

将下列代码复制并替换到StuAdapter中

 

<?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"
    android:minWidth="25px"
    android:minHeight="25px">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="30.5dp"
        android:id="@+id/linearLayout1">
        <TextView
            android:text="姓名:"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textView1" />
        <TextView
            android:text="Text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/name" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout2">
        <TextView
            android:text="年龄:"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textView3" />
        <TextView
            android:text="Text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/age" />
    </LinearLayout>
</LinearLayout>
View Code

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2021-12-04
  • 2022-01-26
  • 2022-12-23
  • 2022-01-22
  • 2021-07-26
猜你喜欢
  • 2021-08-24
  • 2021-09-26
  • 2021-12-27
  • 2021-05-07
  • 2022-12-23
相关资源
相似解决方案