【问题标题】:How to display a listview of custom fragments?如何显示自定义片段的列表视图?
【发布时间】:2011-12-01 06:51:08
【问题描述】:

我使用的是 Android 3.0。我想显示一个包含片段的列表视图。每个片段都包含一个图像、一个描述和一些其他 UI 元素。

我正在寻找一些示例代码或指针。

【问题讨论】:

  • 自定义 ListView 到底是什么意思,因为您也可以在其他 ListView 中拥有图像和描述?

标签: android android-listview android-fragments


【解决方案1】:

您的 Fragment 应该扩展 ListFragment。 ListFragment 参考文档解释了如何使用自定义 ListView 和行布局。

http://developer.android.com/reference/android/app/ListFragment.html

在行布局中(每一行代表一个列表项),可以添加一个ImageView来显示一张图片。

 <ImageView android:id="@+id/imgView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>

 <TextView android:id="@+id/text2"
     android:textSize="16sp"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>

【讨论】:

  • 如果你解释一下你在做什么并粘贴一些代码/日志/堆栈跟踪会更好。 “不工作”是没有建设性的。
  • @Anirudh 感谢您的明确回复。这里的标题不应该显示片段的自定义列表视图。或者在列表视图中显示自定义片段?似乎用户的标题是倒退的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-20
  • 2020-05-24
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 1970-01-01
  • 2015-01-28
相关资源
最近更新 更多