【发布时间】:2018-05-10 13:09:49
【问题描述】:
当用户点击 FULL-TIME 按钮时,我想打开应该显示包含 image、texts 的列表视图的片段,和 3 个点 在每个视图的右端找到下面的图像。怎么做?
.
这是我的代码。 home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/layout_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_full_time"
android:layout_width="191dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:text="@string/full_time" />
<Button
android:id="@+id/btn_part_time"
android:layout_width="206dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/btn_full_time"
android:text="@string/part_time" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layout_2nd">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
我是否需要为每个视图创建单独的 xml,或者我可以通过编程方式进行吗?请推荐?
【问题讨论】:
-
您需要以编程方式使用数据填充 ListView,有很多方法可以做到这一点。也许从这样的事情开始stackoverflow.com/questions/5070830/…
-
您需要创建一个描述单个列表视图项的 xml。然后您需要创建一个适配器类/或者您可以使用您创建的 xml 文件使用 ArrayAdapter 进行初始化。然后将该适配器设置为 listview。
-
是的,所以请查看windrealm.org/tutorials/android/android-listview.php。每个 ListView 项目/部分都需要一个布局...布局将具有看起来像图像、文本视图和按钮的内容。
-
@Danger 还是一针见血。您需要适配器将数据传递到各个列表行(具有布局),然后将其应用于 ListView 本身。
标签: android listview android-fragments android-view android-relativelayout