转换整个列表视图项目(子女)为位图 [英] Converting the entire listview items (children) to bitmap

查看:139
本文介绍了转换整个列表视图项目(子女)为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建为整个列表视图项的位图;目前我下面这个方法:

I have to create the bitmaps for entire listview items; currently I am following this approach:

来捕捉ListView的个别项目我有低于code:

ListView listview = shoppingItemList;
        BaseAdapter adapter = (BaseAdapter) listview.getAdapter();
        int itemscount = adapter.getCount();
        int allitemsheight = 0;
        List<Bitmap> bmps = new ArrayList<Bitmap>();
        System.out.println("In getWholeListViewItemsToBitmap.......");
        for (int i = 0; i < itemscount; i++) {

            View childView = adapter.getView(i, null, listview);            childView.setDrawingCacheEnabled(true);
            childView.measure(
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            childView.layout(0, 0, childView.getMeasuredWidth(),
                    childView.getMeasuredHeight());
            // childView.setDrawingCacheEnabled(true);
            childView.buildDrawingCache(true);
            Bitmap b = Bitmap.createBitmap(childView.getDrawingCache());
            bmps.add(b);
            childView.setDrawingCacheEnabled(true);
            allitemsheight += childView.getMeasuredHeight();

        }

我现在面临的问题是:
我的应用程序退出而不childView.measure后记录任何错误...
任何人都可以请帮我搞清楚究竟是什么问题。

The problem I am facing is that: My application exits without logging any error after childView.measure... Can anyone please help me figuring out what exactly is the issue.

谢谢,
Android开发者

Thanks, Android developer

推荐答案

在列表视图中,在任何时间,只可见孩子们实际创建。因此,你需要更新这是不是在你的适配器的getView方法尚未建立儿童。如果您想更新这是目前可见的孩子,你可以通过列表视图的可见孩子们穿越。下面是一个示例code要做到这一点:

In the list view, at any time, only the visible children are actually created. Therefore, you need to update children which aren't created yet in the getView method of your adapter. If you'd like to update the children which are currently visible, you can traverse through the visible children of the list view. Here's a sample code to do that:

for(int k = 0; k<listView.getChildCount(); k++){
     View child = listView.getChildAt(k);

     // For demo purposes, here I'm just updating a textview, you can do whatever you want
     TextView demo = (TextView) child.findViewById(R.id.demo_text_view);
     demo.setText("demo");
}

这篇关于转换整个列表视图项目(子女)为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆