Android : Creating Multiple Line Listview in Android-Xamarin

on Tuesday, October 7, 2014


I want the listview to display multiple lines of text.2 lines of text in addition to the one displayed. What is the best approach to do this?


For now i have created a simple listview,added a row xml file,and populated the listview in code


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" />


Code



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


I want to display more dynamic data in it.


0 comments:

Post a Comment