I am trying to save a page content in linear layout as an image into the storage of my phone. So I am populating a listview
with all the attendee for certain event. Then, when my print button on click, it should save all the attendees into an image:
btnPrintAttendee.setOnClickListener(new OnClickListener(){
public void onClick(View v){
llAttendeeList.setDrawingCacheEnabled(true);
Bitmap bitmap = llAttendeeList.getDrawingCache();
File file, f = null;
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
file = new File(
android.os.Environment.getExternalStorageDirectory(),
"myfolder");
if (!file.exists()) {
file.mkdirs();
}
f = new File(file.getAbsolutePath() + file.separator + "filename"
+ ".png");
}
FileOutputStream ostream = null;
try {
ostream = new FileOutputStream(f);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
bitmap.compress(CompressFormat.PNG, 10, ostream);
try {
ostream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
With the above code, I am able to save the linear layout as an image into a new generated folder called myfolder
. However, for the listview
, there is a scroll bar. So when I save the linear layout as an image, I thought it will save all the attendees into an image.
Unfortunately, it only saved the attendee on the current screen. Let's say I got 10 attendees but my list view only managed to show 5 on the current screen. The other 5 I have to scroll down. When I save linear layout to image, it only saved up the 5 attendees instead of 10.
Any ideas? Thanks in advance.