在列表视图中格式化文本视图

发布于 2024-12-15 05:41:19 字数 216 浏览 5 评论 0原文

我有一个包含一些项目的 ListView。我想设置 ListView,其中某些项目带有删除线。我知道如何使用 onclicklistener 来实现它,但我想加载带有已标记删除线项目的 ListView 。

所以我启动我的程序,效果应该是这样的:

第一个/strikethrough/

第二个

第三个

第四个/strikethrough/

I have a ListView with some items. I'd like to set ListView where some items are strikethrough. I know how to make it using onclicklistener, but I'd like to load ListView with already marked strikethrough items.

So I start up my programm and an effect should be something like this:

first /strikethrough/

second

third

fourth /strikethrough/

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

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

发布评论

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

评论(2

梦里人 2024-12-22 05:41:19

要自定义列表视图,您可能需要创建一个自定义 ListView ArrayAdapter ,它将加载您的文本视图并将其设置为删除线:

private class ResultsAdapter extends ArrayAdapter<Route> {

    private ArrayList<Route> items;

    public ResultsAdapter(Context context, int textViewResourceId, ArrayList<Route> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.route_row, null);
        }
        Route res = items.get(position);
        if (res != null) {
            TextView line1 = (TextView) v.findViewById(R.id.route_line1);
//setup your strikethrough as needed.

            }

        }
        return v;
    }
}

To customize your list view you probably need to make a Custom ListView ArrayAdapter which will load your text view and set it to strikethrough:

private class ResultsAdapter extends ArrayAdapter<Route> {

    private ArrayList<Route> items;

    public ResultsAdapter(Context context, int textViewResourceId, ArrayList<Route> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.route_row, null);
        }
        Route res = items.get(position);
        if (res != null) {
            TextView line1 = (TextView) v.findViewById(R.id.route_line1);
//setup your strikethrough as needed.

            }

        }
        return v;
    }
}
来日方长 2024-12-22 05:41:19

如果要从 SimpleAdapter 加载数据,请重写 SimpleAdapter.setViewBinder 方法。当您执行 ListView.SetAdapter(SimpleAdapter) 以使用 SimpleAdapter 中的数据填充 Listview 时,将使用此方法。重写此方法以删除所需的行,但请确保包含以下代码行:

TextView tv=(TextView) aView;
tv.setText(aCursor.getString(aColumnIndex));

这些代码是为了确保显示列表视图项目文本。

If you are loading data from a SimpleAdapter, override the SimpleAdapter.setViewBinder method. This method is used when you execute ListView.SetAdapter(SimpleAdapter) to fill your Listview with data from the SimpleAdapter. Override this method to strikethrough your needed rows, but make sure to include the following lines of code:

TextView tv=(TextView) aView;
tv.setText(aCursor.getString(aColumnIndex));

These are to ensure that your listview items text appear.

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