2014-10-07 85 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

相關問題