android - ListView with BaseAdapter doesn't show up If I use horizontal LinearLayout -
i tried implement simple baseadapter. items not displayed in list , list rows seem lean can't shown.
my code bellow.
activity:
public class myactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); listview listview = (listview) findviewbyid(android.r.id.list); listview.setadapter(new baseadapter() { string[] list = new string[] {"spot", "stripe"}; @override public int getcount() { homecoming list.length; } @override public object getitem(int position) { homecoming list[position]; } @override public long getitemid(int position) { homecoming position; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { convertview = getlayoutinflater().inflate(r.layout.item, null); } textview text1 = (textview) convertview.findviewbyid(r.id.text_left); textview text2 = (textview) convertview.findviewbyid(r.id.text_right); text1.settext("name"); text2.settext(getitem(position).tostring()); homecoming convertview; } }); } } activity layout(activity_my.xml):
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".myactivity"> <listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout> listview item layout(item.xml):
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <textview android:id="@+id/text_left" android:textappearance="?android:attr/textappearance" android:layout_width="wrap_content" android:layout_height="match_parent" /> <view android:layout_width="20dp" android:layout_height="1dp"/> <textview android:id="@+id/text_right" android:textappearance="?android:attr/textappearance" android:layout_width="wrap_content" android:layout_height="match_parent" /> </linearlayout> edit:
if alter linearlayout's orientation "vertical" in item.xml item appears. can explain why if set orientation "horizontal" row seems thin?
i found mistake. set layout_height="1dp" in item.xml view placing space between 2 textview. create row's height thin. can't see in listview. if alter "match_parent" same other 2 textview's layout_height, solves problem.
android listview
No comments:
Post a Comment