【问题标题】:List of items with custom views/layouts具有自定义视图/布局的项目列表
【发布时间】:2013-04-09 08:07:24
【问题描述】:

我需要一种方法来创建一个可垂直滚动的列表。然后列表应该包含一堆行,其中每行应该有一个图像按钮、一个图像、三个TextViews 和两个图像。 像这样:

Row1: ImgBtn | TextView | TextView | TextView | Image | Image 

Row2: ImgBtn | TextView | TextView | TextView | Image | Image 

Row3: ImgBtn | TextView | TextView | TextView | Image | Image

..等等..

我还需要将视图“绑定”到某些值。因为TextViews 的值和图像等应该从数据库中“获取”。

问题:

什么是最好的方法,有什么地方可以让我了解更多关于这个的信息吗?.. 我不太确定要谷歌什么,所以这就是为什么我自己问而不是谷歌搜索的原因之一 :)

提前致谢!

【问题讨论】:

    标签: android list listview data-binding scroll


    【解决方案1】:

    您可以查看我写的关于如何创建自定义 ListView 的指南:

    Custom ListView

    基本上你需要创建一个CustomArrayAdapter,阅读指南以了解它是如何完成的。

    【讨论】:

      【解决方案2】:

      你想要的是一个组件。组件是不同于 Android 直接为您提供的自定义对象。更多信息在这里:

      http://developer.android.com/guide/topics/ui/custom-components.html

      制作自定义组件后,您只需在 getView() 上实例化自定义项

      【讨论】:

        【解决方案3】:

        您应该扩展 BaseAdapter 并定义您自己的适配器,ListView 将使用该适配器。
        以下是一些展示如何操作的文章:
        http://www.ezzylearning.com/tutorial.aspx?tid=1763429
        http://androidresearch.wordpress.com/2012/01/07/building-a-custom-fancy-listview-in-android/

        【讨论】:

          【解决方案4】:

          如果您打算创建自定义列表视图,则应使用扩展“arrayAdapter”。也许本教程会对您有所帮助:http://www.vogella.com/articles/AndroidListView/article.html

          【讨论】:

            【解决方案5】:

            您可以根据需要编写自定义布局并使用它来代替 android.R.layout.simple_list_item_1 并使用 android.layout.yourxml,在 google 中搜索你怎么能做到这一点,你也可以搜索你想要做什么来使用适配器自定义 android listview

            【讨论】:

              【解决方案6】:

              好吧,您不需要自定义视图,您只需要将布局设置为 row_layout 或任何其他名称,如下所示:

              <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal" >
              
              <ImageButton
                  android:id="@+id/imageButton1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/ic_action_lang" />
              
              <TextView
                  android:id="@+id/textView1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="TextView" />
              
              <TextView
                  android:id="@+id/textView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="TextView" />
              
              <ImageView
                  android:id="@+id/imageView1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/ic_action_lang" />
              
              <ImageView
                  android:id="@+id/imageView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/ic_action_lang" />
              

              然后在适配器中对其进行膨胀,然后将数据分配给该视图,例如来自您的数据库。您需要的步骤是:

              • 制作布局
              • 列表视图
              • 适配器(根据您的布局将数据逐行分配给 listView) 过去几周我自己在学习列表,一开始看起来很长 但是当您获得该过程时会变得非常容易,因此这里有一些可能对您有所帮助的链接:

              • Android offical website

              • Vogella

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-11-06
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-09-22
                相关资源
                最近更新 更多