2014-10-07 88 views
0

我希望列表视图除了显示的行之外还显示多行文本。 这样做的最佳方法是什么?在Android中创建多行列表视图-Xamarin

现在我已经创建了一个简单的列表视图,增加了一个排的XML文件,并填充ListView控件代码

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; 
     } 
    } 
} 

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

+0

你是说你想添加或删除列表项目动态? – 2016-04-14 10:26:42

回答

0

您将子类BaseAdapter或BaseAdapter < T>和处理项目视图创建。阅读this document

相关问题