如何从ListView项目中获取ImageView?

发布于 2024-11-28 11:10:33 字数 286 浏览 4 评论 0原文

我有一个列表活动,我想将图像资源设置为列表视图项中的图像视图。

        ListView listView = getListView();
        View view = listView.getChildAt(0);
        arrowImageView = (ImageView)view.findViewById(R.id.arrowImageView);

但 getChildAt(0) 返回 null。列表有 10 项。 我如何找到 ImageView?

I have a list Activity and I want set image resource to Image view in list view item.

        ListView listView = getListView();
        View view = listView.getChildAt(0);
        arrowImageView = (ImageView)view.findViewById(R.id.arrowImageView);

but getChildAt(0) return null. List have 10 items.
How i can find a ImageView?

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

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

发布评论

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

评论(1

蛮可爱 2024-12-05 11:10:33

编辑
我想您是在问如何在列表视图的每个项目中设置图像资源?如果是这样,请扩展您的 SimpleCursorAdapter 并重写 getView ,类似于以下内容:

// Create the list adapter
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
        CfsApplication.getApplication(),
        R.layout.listitem_vehicledraft,
        VehicleDraftTable.getAllVehicleDrafts(),
        displayFields,
        displayViews) {
    /* (non-Javadoc)
     * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Get the view from the super function which will handle most of everthing for us
        convertView = super.getView(position, convertView, parent);

        // Set the image view here
                    // ...

        // Return the view
        return convertView;
    }
};

Edit
I think you're asking how to set an image resource in each item of your list view? If so, extend your SimpleCursorAdapter and override getView similar to this:

// Create the list adapter
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
        CfsApplication.getApplication(),
        R.layout.listitem_vehicledraft,
        VehicleDraftTable.getAllVehicleDrafts(),
        displayFields,
        displayViews) {
    /* (non-Javadoc)
     * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Get the view from the super function which will handle most of everthing for us
        convertView = super.getView(position, convertView, parent);

        // Set the image view here
                    // ...

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