具有自定义视图的 GridView

发布于 2024-09-30 00:08:19 字数 589 浏览 0 评论 0原文

我不知道这是否可能,但实际上我不明白为什么不可以。

我们不仅可以使用 ImageView 还可以使用自定义视图来制作网格视图吗?

我正在尝试制作由 ImageView 和 TextView 组成的视图的网格视图。

我知道一切都发生在我的 Adapter getView 函数中,但我不知道该怎么做。

public View getView(int position, View convertView, ViewGroup parent) {
    View cases = findViewById(R.id.fileUnitLayout);

    if (convertView == null) {
       convertView = new View(mContext);
    } else {
       cases = convertView;
    }

       return cases;
    }

我的视图的 id 为 R.id.fileUnitLayout。假设我的内部 TextView 的 id 为 A,我的内部 ImageView 的 id 为 B。我该如何填充它们?

谢谢你,

I don't know if it is possible, but actually I wouldn't see why not.

Can we do a grid view not just with ImageView but with a custom view.

I am trying to make a grid view of a view composed of an ImageView and a TextView.

I know that everything happens in my Adapter getView's function but I can't figure out how to do it.

public View getView(int position, View convertView, ViewGroup parent) {
    View cases = findViewById(R.id.fileUnitLayout);

    if (convertView == null) {
       convertView = new View(mContext);
    } else {
       cases = convertView;
    }

       return cases;
    }

My view has an id of R.id.fileUnitLayout. Let's say my inner TextView has an id of A and my inner ImageView has an id of B. How can I fill them ?

Thank you,

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

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

发布评论

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

评论(1

戒ㄋ 2024-10-07 00:08:19

您不一定需要重写 getView 来完成此操作。 GridView 是一个 AdapterView,因此您可以提供一个适配器,通过 setAdapter

例如,您可以使用 SimpleAdapter 提供用于每个网格视图项的 xml 文件。

You should not need to override getView to accomplish this, necessarily. GridView is an AdapterView so you can provide an adapter that will display what you want via setAdapter

You could, for example, use SimpleAdapter to provide an xml file that is used for each grid view item.

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