2014-10-08 149 views
0

我有一個自定義列表視圖,我需要的2個標籤顯示列表視圖

我有馬寧佈局這樣的一個內顯示(main.axml

<?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> 

的列表項是這樣的(simplerow.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#808080" 
    android:padding="5dip"> 
    <ImageView 
     android:id="@+id/leftImage" 
     android:layout_height="match_parent" 
     android:layout_width="5dip" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/ic_indicator_green" /> 
    <ImageView 
     android:id="@+id/rightImage" 
     android:layout_width="10dip" 
     android:layout_height="10dip" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="10dip" 
     android:src="@drawable/ic_alert" /> 
    <TextView 
     android:id="@+id/rowTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@id/leftImage" 
     android:layout_toLeftOf="@id/rightImage" 
     android:padding="10dp" 
     android:textSize="16sp" 
     android:textColor="#000000" /> 
</RelativeLayout> 

,我已經創建了一個customlistadaptor(CustomAdaptor.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Android.Graphics.Drawables; 

namespace uitest 
{ 
    public class CustomAdapter : BaseAdapter 
    { 
     Activity context; 

     public List<String> items; 

     public CustomAdapter(Activity context) //We need a context to inflate our row view from 
      : base() 
     { 
      this.context = context; 

      //For demo purposes we hard code some data here 
      this.items = new List<String>() { 
       "data 1", "data 2", "data 3", "data 4" 
      }; 

     } 

     public override int Count 
     { 
      get { return items.Count; } 
     } 

     public override Java.Lang.Object GetItem(int position) 
     { 
      return position; 
     } 

     public override long GetItemId(int position) 
     { 
      return position; 
     } 

     public override View GetView(int position, View convertView, ViewGroup parent) 
     { 
      //Get our object for this position 
      var item = items[position];   

      //Try to reuse convertView if it's not null, otherwise inflate it from our item layout 
      // This gives us some performance gains by not always inflating a new view 
      // This will sound familiar to MonoTouch developers with UITableViewCell.DequeueReusableCell() 
      var view = (convertView ?? 
       context.LayoutInflater.Inflate(
        Resource.Layout.simplerow, 
        parent, 
        false)) as RelativeLayout; 

      var rowTextView = view.FindViewById(Resource.Id.rowTextView) as TextView; 
      rowTextView.SetText(item, TextView.BufferType.Normal); 

      //Find references to each subview in the list item's view 
      // var imageItem = view.FindViewById(Resource.id.imageItem) as ImageView; 
      // var textTop = view.FindViewById(Resource.id.textTop) as TextView; 
      // var textBottom = view.FindViewById(Resource.id.textBottom) as TextView; 

      //Assign this item's values to the various subviews 
      // imageItem.SetImageResource(item.Image); 
      // textTop.SetText(item.Name, TextView.BufferType.Normal); 
      // textBottom.SetText(item.Description, TextView.BufferType.Normal); 

      //Finally return the view 
      return view; 
     } 

     public String GetItemAtPosition(int position) 
     { 
      return items[position]; 
     } 
    } 
} 

在MainActivity

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.SimpleListItem1, //The layout. How the data will be presented 
      // kittens //The enumerable data 
      //); 
      // this.ListAdapter = adapter; 

      var customAdapter = new CustomAdapter (this); 
      this.ListAdapter = customAdapter; 

     } 
    } 
} 

現在,我嘗試了2 tabs.Im的一個漂亮的新內顯示此內容android.Should我創建單獨的活動在選項卡內創建視圖還是有一種方法來添加這個事情我已創建到一個簡單的方式選項卡。

回答

0

您可以創建選項卡,也可以使用片段,然後使用操作選項卡切換它們。 這是一個Xamarin article explaining它。