Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在选项卡中显示listview-Android Xamarin_Android_Xml_Listview_Mono_Xamarin - Fatal编程技术网

在选项卡中显示listview-Android Xamarin

在选项卡中显示listview-Android Xamarin,android,xml,listview,mono,xamarin,Android,Xml,Listview,Mono,Xamarin,我有一个自定义的listview,我需要在两个选项卡之一中显示它 我有这样的manin布局main.axml 现在,我正在尝试在两个选项卡中的一个选项卡中显示此内容。我对android非常陌生。我应该在选项卡中创建单独的活动来创建视图,还是有办法将我创建的内容轻松添加到选项卡中。您可以创建选项卡,也可以使用片段,然后用操作选项卡切换它们。 这里有一个例子 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and

我有一个自定义的listview,我需要在两个选项卡之一中显示它

我有这样的manin布局main.axml


现在,我正在尝试在两个选项卡中的一个选项卡中显示此内容。我对android非常陌生。我应该在选项卡中创建单独的活动来创建视图,还是有办法将我创建的内容轻松添加到选项卡中。

您可以创建选项卡,也可以使用片段,然后用操作选项卡切换它们。 这里有一个例子

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

        }
    }
}