【问题标题】:How to customize the just the first line of a ListView?如何自定义 ListView 的第一行?
【发布时间】:2014-10-04 19:05:35
【问题描述】:

我创建了一个 ListView,它的条目是在 SQLite 查询中用一段时间生成的,除了我在代码中写的第一行。

这里是相关的 XML 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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


</LinearLayout>

如何自定义仅更改ListView第一行的字体样式?

【问题讨论】:

  • 在代码中添加标题视图并为其分配自定义布局。
  • 我做到了,现在如何添加内容?
  • 和往常一样,在你的添加布局中找到TextView的id,然后使用setText()添加你要显示的文字。

标签: android listview customization except


【解决方案1】:

如果您只想更改第一行的样式或布局,可以使用列表视图标题

【讨论】:

  • 我添加这段代码: View headerView = ((LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE)).inflate(R.layout.stat_list_header, null, false); lview.addHeaderView(headerView);但什么也没发生。现在怎么填?
  • 如果你在 customHeaderLayout(R.layout.stat_list_header) 中有 textView,你可以找到它的 id,比如 TextView tx = (TextView)headerView.findViewById(R.id.text_id);然后就做 tx.setText("your text");
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 1970-01-01
  • 2016-07-23
  • 1970-01-01
  • 2020-09-29
相关资源
最近更新 更多