【问题标题】:Creating Multiple Line Listview in Android-Xamarin在 Android-Xamarin 中创建多行列表视图
【发布时间】:2014-10-07 12:14:16
【问题描述】:

我希望列表视图显示多行文本。除了显示的那一行之外,还有 2 行文本。 最好的方法是什么?

现在我已经创建了一个简单的列表视图,添加了一个行 xml 文件,并在代码中填充了列表视图

Main.xml

<?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">
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/mainListView" />
</LinearLayout>

Row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rowTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:textSize="16sp" />

代码

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace uitest
{
    [Activity (Label = "uitest", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity :ListActivity
    {


        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            var kittens = new [] { "Fluffy", "Muffy", "Tuffy" };

            var adapter = new ArrayAdapter (
                this, //Context, typically the Activity
                Android.Resource.Layout.SimpleListItem2, //The layout. How the data will be presented 
                kittens //The enumerable data
            );

            this.ListAdapter = adapter; 
        }
    }
}

我想在其中显示更多动态数据。

【问题讨论】:

  • 您是说要动态添加或删除列表项吗?

标签: c# android listview mono xamarin


【解决方案1】:

您将继承 BaseAdapter 或 BaseAdapter 并处理项目视图的创建。阅读this document

【讨论】:

    猜你喜欢
    • 2013-07-21
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 2014-10-15
    • 1970-01-01
    • 2021-08-06
    • 2011-08-30
    • 1970-01-01
    相关资源
    最近更新 更多