开发者

ListView doesn't show first textview item

I am trying to make a listview, every row 开发者_StackOverflow中文版contains an imageview and two text views. The image and the second textview is shown but the first textview is blank...Can't figure out what's wrong...I can't wrap my head around custom list adapters...I have read http://commonsware.com/Android/excerpt.pdf to.

My data is loaded correctly to the arraylist. My code:

private class SongAdapter extends ArrayAdapter<Szam> {

        private ArrayList<Szam> items;

        public SongAdapter(Context context, int textViewResourceId,     ArrayList<Szam> items) {
                super(context, textViewResourceId, items);
                this.items = items;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate(R.layout.row, null);
                }
                Szam o = items.get(position);
                if (o != null) {
                        TextView tt = (TextView) v.findViewById(R.id.firstLine);
                        TextView bt = (TextView) v.findViewById(R.id.secondLine);
                        if (tt != null) {
                              tt.setText(o.getArtist());                            }
                        if(bt != null){
                              bt.setText(o.getTitle());
                        }
                }
                return v;
        }

And my xml layout:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"     android:minHeight="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content" android:padding="6dip">

<TextView android:id="@+id/secondLine" android:layout_width="fill_parent"
    android:layout_height="26dip" android:layout_toRightOf="@+id/icon"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" android:singleLine="true"
    android:ellipsize="marquee"
    android:text="Simple application that shows how to use RelativeLayout" />

<TextView android:id="@+id/firstLine" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_toRightOf="@+id/icon"
    android:layout_alignParentRight="true" android:layout_alignParentTop="true"
    android:layout_above="@id/secondLine"
    android:layout_alignWithParentIfMissing="true" android:gravity="center_vertical"
    android:text="My Application" />
<ImageView android:layout_marginRight="6dip" android:id="@+id/icon"
    android:src="@drawable/play" android:layout_width="wrap_content"
    android:layout_height="fill_parent" android:layout_alignParentLeft="true"></ImageView>

 </RelativeLayout>

The corrected layout is:

<TextView android:id="@+id/secondLine1" android:layout_width="fill_parent"
    android:layout_height="wrap_content"  android:layout_toRightOf="@+id/icon"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" android:singleLine="true"
    android:ellipsize="marquee"
    android:textColor="#ffffff"

    android:textSize="12sp"
    android:text="Simple application that shows how to use RelativeLayout" />

<TextView android:id="@+id/firstLine1" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_toRightOf="@+id/icon"
    android:layout_alignParentRight="true" android:layout_alignParentTop="true"
    android:ellipsize="marquee"
    android:textColor="#ffffff"

    android:textSize="16sp" 
    android:layout_alignWithParentIfMissing="true"
    android:text="My Application" />

<ImageView android:layout_marginRight="6dip" android:id="@+id/icon"
    android:src="@drawable/play" android:layout_width="wrap_content"
    android:layout_height="fill_parent" android:layout_alignParentLeft="true"></ImageView>


Can't you use LinearLayouts?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
    android:minHeight="?android:attr/listPreferredItemHeight" android:layout_height="wrap_content" android:padding="6dip">
    <ImageView android:layout_marginRight="6dip" android:id="@+id/icon" android:src="@drawable/play" android:layout_width="wrap_content"
        android:layout_height="fill_parent"></ImageView>
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:orientation="vertical"
        android:layout_height="wrap_content">
        <TextView android:text="My Application" android:layout_height="wrap_content" android:gravity="center_vertical" android:id="@+id/firstLine"
            android:layout_width="fill_parent"></TextView>
        <TextView android:singleLine="true" android:text="Simple application that shows how to use RelativeLayout" android:layout_height="wrap_content"
            android:ellipsize="marquee" android:id="@+id/secondLine" android:layout_width="fill_parent"></TextView>
    </LinearLayout>
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜