when the user selects a share button within an activity, I would like to inflate a layout, populate it, and then write that layout to a pdf using the new printing API.
In my fragment I have
@TargetApi(Build.VERSION_CODES.KITKAT)
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share_context:
LayoutInflator inflator = getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View container = inflator.inflate(R.layout.person_share, null, false);
TextView name = (TextView)topContainer.findViewById(R.id.person_name);
name.setText("Test Name");
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(612, 792, 1).create()
PdfDocument.Page page = document.startPage(pageInfo)
container.draw(page.getCanvas());
document.finishPage(page)
// write pdf
...
This unfortunately outputs a blank pdf document. However, when I use a view that already exists on the screen (inflated in onCreateView(..)), it shows up in the pdf as expected.
I'd appreciate any help.