设置列表视图项的特定部分的格式

发布于 2024-11-14 06:26:54 字数 1582 浏览 3 评论 0原文

因此,在我的应用程序中,我使用 ListView 来显示包含对象的 ArrayList 中的数据。使用与 android 开发人员网站上的教程相同的方法显示数据:

        // automatically adds a ListView to fill the entire screen of this activity
    setListAdapter(new ArrayAdapter<Part>(this, R.layout.list_item, Main.parts));
    ListView lv = getListView();        

    // allows the user to start typing to filter the list
    lv.setTextFilterEnabled(true);       

    // set the click listener for each list item
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });

对象当前显示在每个 list_item 中:

<!-- Defines the layout for each item being placed in the ListView. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

因此,我按如下方式返回每个对象:

    public String toString() {
    return "Item Number: " + itemNmbr + "\nPrice: " + price + "\nDescription: " + desc;
}

列表当前外观的示例:

http://imageshack.us/photo/my-images/689/devicet.png/

问题是,我需要将标题与数据分开格式化。 (因为它需要加粗,并且可能间隔得更远一些。)

有什么想法吗?我目前正在测试如何让两个文本视图一起工作。

谢谢你!

So in my application I am using a ListView to display data from an ArrayList which holds objects. The data is displayed using the same method as the tutorial on the android developer website:

        // automatically adds a ListView to fill the entire screen of this activity
    setListAdapter(new ArrayAdapter<Part>(this, R.layout.list_item, Main.parts));
    ListView lv = getListView();        

    // allows the user to start typing to filter the list
    lv.setTextFilterEnabled(true);       

    // set the click listener for each list item
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });

The objects are currently displayed in each list_item:

<!-- Defines the layout for each item being placed in the ListView. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

So I return each object as such:

    public String toString() {
    return "Item Number: " + itemNmbr + "\nPrice: " + price + "\nDescription: " + desc;
}

An example of how the list currently looks:

http://imageshack.us/photo/my-images/689/devicet.png/

The problem is, I need to format the title separately from the data. (because it needs to be bold, and possibly spaced out a little further.)

Any ideas? I'm currently testing on how to get two textviews to work together.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文