0

我知道由于 Android 问题,我无法在滚动视图中创建 ListView。尽管有可用的 hack,但我不确定它是否与旧的 Android SDK 兼容。所以想做不同的布局。

<RelativeLayout ID=R1>
<TextView ID=A1 layout_weight=0.5>
<ImageView ID=A2 layout_weight=0.5>
</RelativeLayout>

数据库:字符串数组 textView 值:1、2、3、4、5 和 ImageView 值:A、B、C、D、E。

现在,我想在 RelativeLayout 中动态添加数据库值

- Calculate the max number of values available to add in TextView and ImageView
- Start a for loop and read data from the array
- Add data from the array creating a new row for every (TextView, ImageView)

有人可以帮我创建这个适配器吗?我尝试修改我的 listView 适配器,但不知何故它不适用于 RelativeLayout,因为参数 setAdapter 不适用于 RelativeLayout。此外,继续前进,我想通过 excel 表连接这些数据。任何帮助,将不胜感激。谢谢!

4

1 回答 1

0

可能这会有所帮助

void init() {
    LinearLayout linearLayout = findById(.......);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    for (Worker worker : workers) {
        Button button = new Button(getActivity());
        button.setText(worker.toString());
        button.setId(5);
        linearLayout.addView(button);
    }
}

和布局:

<?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="match_parent"
                android:id="@+id/linearLayout1">

</LinearLayout>
于 2013-09-19T06:02:31.977 回答