xml - Display listview within Tabs- Android Xamarin -
i have custom listview need display within 1 of 2 tabs
i have manin layout (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> the listitem goes (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> and have created 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 context inflate our row view : base() { this.context = context; //for demo purposes hard code info here this.items = new list<string> () { "data 1", "data 2", "data 3", "data 4" }; } public override int count { { homecoming items.count; } } public override java.lang.object getitem(int position) { homecoming position; } public override long getitemid(int position) { homecoming position; } public override view getview(int position, view convertview, viewgroup parent) { //get our object position var item = items[position]; //try reuse convertview if it's not null, otherwise inflate our item layout // gives performance gains not inflating new view // sound familiar monotouch developers uitableviewcell.dequeuereusablecell() var view = (convertview ?? context.layoutinflater.inflate( resource.layout.simplerow, parent, false)) relativelayout; var rowtextview = view.findviewbyid(resource.id.rowtextview) textview; rowtextview.settext(item, textview.buffertype.normal); //find references each subview in list item's view // var imageitem = view.findviewbyid(resource.id.imageitem) imageview; // var texttop = view.findviewbyid(resource.id.texttop) textview; // var textbottom = view.findviewbyid(resource.id.textbottom) textview; //assign item's values various subviews // imageitem.setimageresource(item.image); // texttop.settext(item.name, textview.buffertype.normal); // textbottom.settext(item.description, textview.buffertype.normal); //finally homecoming view homecoming view; } public string getitematposition(int position) { homecoming items[position]; } } } the 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 activity // android.resource.layout.simplelistitem1, //the layout. how info presented // kittens //the enumerable info //); // this.listadapter = adapter; var customadapter = new customadapter (this); this.listadapter = customadapter; } } } now im trying display content within 1 of 2 tabs.im pretty new android.should create separate activities creating views within tabs or there way add together thing have created tab in easy way.
you can create tabs or can utilize fragments , switch them action tabs. here's xamarin article explaining it.
android xml listview mono xamarin
No comments:
Post a Comment