【问题标题】:I have a list view, i i need to populate a custom row layout with two edit text,two button and chekbox for each. what should i do?我有一个列表视图,我需要使用两个编辑文本、两个按钮和每个复选框填充自定义行布局。我该怎么办?
【发布时间】:2015-10-16 15:12:40
【问题描述】:

自定义布局将是这样的 我需要使用两个编辑文本、两个按钮和每个复选框填充自定义行布局。我该怎么办。

    ||EDIT_TEXT            ||Button 
    """""""""""" 
    ||EDIT_TEXT
    """"""""""""
    ||Chekbox  ||Chekbox  ||Button

我的自定义布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <EditText
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:id="@+id/etPhone"
            android:maxLength="15"
            android:text=""
            android:lines="1"
            android:hint=" Phone Number"
            android:inputType="number"
            android:background="@drawable/edittext_bottom_bg"
            android:digits="0123456789"
            android:drawableLeft="@drawable/mobile"
            android:layout_alignBottom="@+id/etAmount"
            android:layout_alignLeft="@+id/etAmount"
            android:layout_alignStart="@+id/etAmount" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="X"
            android:id="@+id/button2"
            android:layout_column="5" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <EditText
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:id="@+id/etAmount"
            android:hint="  Amount"
            android:maxLength="10"
            android:lines="1"
            android:text=""
            android:inputType="number"
            android:digits="0123456789"
            android:background="@drawable/edittext_bottom_bg"
            android:drawableLeft="@drawable/money"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_column="0">

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:text="PRE"
                android:id="@+id/checkBox"
                android:layout_weight="1" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:text="POST"
                android:id="@+id/checkBox2"
                android:layout_weight="1" />
        </TableRow>

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SEND"
            android:id="@+id/button"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>
</TableLayout>

我的主列表视图布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/a8">

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/lvShow" />

就是这样。我没有为此创建任何类,我只想通过单击按钮在列表视图中显示该行

【问题讨论】:

  • 你试过我的伪代码了吗?
  • 我给你的答案是一个只有最重要的东西让你知道的布局。其余的布局你必须自己填写。像宽度,高度,也许是重量

标签: android android-listview custom-lists


【解决方案1】:

这样的布局

<LinearLayout orientation:vertical>

   <linearLayout orientation:horizontal>
      <EditText/>
      <Button/>
   </LinearLayout>

   <EditText/>

   <LinearLayout orientation:horizontal>
      <CheckBox/>
      <CheckBox/>
      <CheckBox/>
  </LinearLayout>

<LinearLayout>

【讨论】:

    【解决方案2】:

    您必须创建自定义 ListView。按照教程https://www.caveofprogramming.com/guest-posts/custom-listview-with-imageview-and-textview-in-android.html 并根据需要使用您的xml 视图更新本教程中的program_list.xml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多