如何夸大一个的LinearLayout作为行? [英] How to inflate a linearlayout as a row?

查看:91
本文介绍了如何夸大一个的LinearLayout作为行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想填充从数据库项目列表。
我想一个膨胀作为的LinearLayout行,而不是常规的行显示ImageView的。

I am trying to populate a list of items from a database. I want to inflate a linearLayout as the row instead of a regular row to show a imageView.

下面是我的XML为我row.xml的LinearLayout。

Here is my XML for My row.xml linearLayout.

  ?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"
android:padding="4dip">
      <ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentTop = "true"
    android:layout_alignParentBottom = "true"
    android:layout_marginRight="4dip"
           />
           <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
        android:textColor="#15317E"
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textStyle="bold"
            android:maxLines="1"
            android:textSize="21dip"
            android:ellipsize="end"
            />




        </LinearLayout>
             </LinearLayout>

现在在这里,我用一个SimpleCursorAdapter在list.xml显示布局

Now Here i use a SimpleCursorAdapter to show the layout in the list.xml

public void fillData(){
            helper.open();
            Cursor task = helper.fetchAllTask();
            startManagingCursor(task);

            String[] from = new String[]{TaskHelper.KEY_TITLE};
            int[] to = new int[]{R.layout.row};

            SimpleCursorAdapter taskAdapter = new SimpleCursorAdapter(this, R.layout.list, task, from , to);
            setListAdapter(taskAdapter);

        }

林不知道,如果IM这样做的权利,如果有人熟悉。请告诉我。
谢谢

Im not sure if im doing this right, If someone is familiar with this. please let me know. Thanks

在我fillData()我想在这上面显示的ImageView为图标也。但它不会填充由于某种原因,每次我添加一个项目。也许它一个更好的办法,我可以重建整个列表。

In my fillData() i would like to show imageView in it as icon also. But it wont populate for some reason everytime i add a item. Maybe its a better way i can reconstruct the whole list.

推荐答案

尝试:

String[] from = new String[]{TaskHelper.KEY_TITLE};
int[] to = new int[]{R.id.title};
SimpleCursorAdapter taskAdapter = new SimpleCursorAdapter(this, R.layout.row, 
    task, from , to);

这篇关于如何夸大一个的LinearLayout作为行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆