Sunday 15 June 2014

android - ListView doesn't appear in xamarin -



android - ListView doesn't appear in xamarin -

greetings i'm trying develop android app using xamarin layout has view pager 8 elements each list view in ... every thing works fine i'm next tutorial here listview doesnot appear here axml list view

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:fitssystemwindows="true"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview1" android:textcolor="#ffffffff" /> <checkbox android:text="@string/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox1" android:textcolor="#ffffffff" /> <checkbox android:text="alert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox2" android:textcolor="#ffffffff" /> </linearlayout> <listview android:id="@+id/newsfeedlist" android:layout_width="fill_parent" android:layout_height="fill_parent" android:dividerheight="10.0sp" /> </linearlayout>

and here axml code listview cell

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <imageview android:id="@+id/contentimageview1" android:src="@android:drawable/ic_menu_gallery" android:layout_width="50dp" android:layout_height="50dp" /> <textview android:id="@+id/contenttextview1" android:text="text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="#ffffffff" /> </linearlayout>

and next code viewpager fragment

using system; using android.support.v4.app; using android.support.v4.view; using android.app; using android.views; using android.os; using android.widget; using android.content; namespace test { public class contentfragment : android.support.v4.app.fragment { private viewpager homeviewpager; public contentfragment () { } override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){ var rootview = inflater.inflate(resource.layout.homecontent, container,false); homeviewpager = rootview.findviewbyid<viewpager> (resource.id.homeviewpager); homeviewpager.adapter = new homepageradapter (mainactivity.fragmentmanager); homecoming rootview; } } }

and next adapter view pager

using system; using android.support.v4.app; namespace test { public class homepageradapter:fragmentpageradapter { public homepageradapter (fragmentmanager fm):base(fm) { } public override int count { { homecoming 8; } } public override fragment getitem (int position) { //return listfragment; homecoming new feedsfragment (); //return f; } } }

following code listview fragment

namespace test { public class feedsfragment:fragment { listview feedslist; list<feedsmodel>modellist; feedsmodel model; public override view oncreateview (layoutinflater inflater, viewgroup container, android.os.bundle savedinstancestate) { try{ view rootview = inflater.inflate (resource.layout.newsfeedlist, container, false); model = new feedsmodel (); modellist=new list<feedsmodel>(); feedslist = rootview.findviewbyid<listview> (resource.id.newsfeedlist); (int = 0; < 5; i++) { model.feedcontent="once upon time tow boys , girl saied bla bla bla , did blablablab , tha't text yup uakfjjkd;f"; model.imageuri = "g"; modellist.add(model); } feedslist.adapter = new feedsadapter (mainactivity.context, modellist); homecoming rootview;} catch(exception e){{ toast.maketext (mainactivity.context, e.message, toastlength.long).show(); homecoming base.oncreateview (inflater, container, savedinstancestate);} } } } }

following adapter listview

amespace test { public class feedsadapter:baseadapter<feedsmodel> { private activity activity; private list<feedsmodel> data; public feedsadapter (activity activity, list<feedsmodel> data):base() { // todo auto-generated constructor stub this.activity = activity; this.data = data; } public override long getitemid(int position) { homecoming position; } public override feedsmodel this[int position] { { homecoming data[position]; } } public override int count { { homecoming data.count; } } public override view getview(int position, view convertview, viewgroup parent) { view view = convertview; // re-use existing view, if 1 available if (view == null) // otherwise create new 1 view = activity.layoutinflater.inflate(resource.layout.newsfeedlistitem, null); toast.maketext (activity, "tetet", toastlength.long).show (); view.findviewbyid<textview>(resource.id.contenttextview1).text = data[position].feedcontent; view.findviewbyid<imageview> (resource.id.contentimageview1).setimageresource(resource.drawable.icon); homecoming view; } } }

finally info model

using system; namespace test { public class feedsmodel { private string _imageuri; public string imageuri{ set{this._imageuri=value;} get{return this._imageuri;} } private string _feedcontent; public string feedcontent{ set{this._feedcontent=value;} get{return this._feedcontent;} } public feedsmodel () { } } }

thanks help in advance

pretty sure you've accidentally set android:orientation horizontal instead of vertical in root layout:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" <-- set vertical android:fitssystemwindows="true"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview1" android:textcolor="#ffffffff" /> <checkbox android:text="@string/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox1" android:textcolor="#ffffffff" /> <checkbox android:text="alert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox2" android:textcolor="#ffffffff" /> </linearlayout> <listview android:id="@+id/newsfeedlist" android:layout_width="fill_parent" android:layout_height="fill_parent" android:dividerheight="10.0sp" /> </linearlayout>

android listview android-fragments android-listview xamarin

No comments:

Post a Comment