0

Trying to take screenshot of dynamic listview ,here is my code

public static Bitmap getWholeListViewItemsToBitmap() {

ListView listview    = MyActivity.mFocusedListView;
ListAdapter adapter  = listview.getAdapter(); 
int itemscount       = adapter.getCount();
int allitemsheight   = 0;
List<Bitmap> bmps    = new ArrayList<Bitmap>();

for (int i = 0; i < itemscount; i++) {

    View childView      = adapter.getView(i, null, listview);
    childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY), 
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

    childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
    childView.setDrawingCacheEnabled(true);
    childView.buildDrawingCache();
    bmps.add(childView.getDrawingCache());
    allitemsheight+=childView.getMeasuredHeight();
}

Bitmap bigbitmap    = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888);
Canvas bigcanvas    = new Canvas(bigbitmap);

Paint paint = new Paint();
int iHeight = 0;

for (int i = 0; i < bmps.size(); i++) {
    Bitmap bmp = bmps.get(i);
    bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
    iHeight+=bmp.getHeight();

    bmp.recycle();
    bmp=null;
}


    return bigbitmap;
}

here i am getting nullpointer exception(listview.getAdapter())could anyone suggest me how to fix this problem . Following this also

Community
  • 1
  • 1
  • Here i declared mFocusedListView as global variable and initializing in onCreate() by getting id ,now i am accessing it from above instance method,here it is not getting id of the listview .help me here –  Feb 12 '14 at 06:42

2 Answers2

0

can't really see the code but your listview is null.

ListView listview    = MyActivity.mFocusedListView;

ListView listview = (ListView)findById(R.id.YOURLISTVIEW);

thats why it is null. post your xml so we can see what the id is.

reidisaki
  • 1,525
  • 16
  • 29
  • http://codeshare.io/6LlWO –  Feb 12 '14 at 03:44
  • Here is xml file http://codeshare.io/O7o7L –  Feb 12 '14 at 03:47
  • Here i am getting listview in my activity with that id.so that i can able to display listview. –  Feb 12 '14 at 03:49
  • great so the listView is no longer null and you are trying to get a screen shot of the items in the listview? can't you use ddms to get a screen shot of whats on the phone? Sorry I'm unsure of your question. – reidisaki Feb 12 '14 at 03:54
  • Want to take screenshot of dynamic listview ,means my listview contains 150+ list items ,if take normal screen capture i will get list items which are visible in screen but i want total list items screenshot .Sorry this is max english. –  Feb 12 '14 at 03:59
0

While it is impossible to make a screenshot of not-yet-rendered content (like off-screen items of the ListView), you can make a multiple screenshots, scroll content between each shot, then stitch images. Here is a tool which can automate this for you: https://github.com/PGSSoft/scrollscreenshot

illustration

Disclaimer: I'm author of this tool, it was published by my employer. Feature requests are welcome.

tomash
  • 12,742
  • 15
  • 64
  • 81