【问题标题】:CheckBox does not toggle on in PDF view in AndroidCheckBox 不会在 Android 的 PDF 视图中打开
【发布时间】:2019-03-15 11:22:08
【问题描述】:

当我将布局转换为 PDF 时,Name 即使在 PDF 中也会显示文本,但 CheckBox 不会在 PDF 中打开。

我尝试在 XML 布局中打开 CheckBox 切换开关,当我转换为 PDF 时,CheckBox 显示正确,但以编程方式不起作用。

TextView tvName = content.findViewById(R.id.txtNameInsert);
CheckBox chM = content.findViewById(R.id.checkMinsert);

tvName.setText(Name.getText());
chM.toggle();

content.draw(page.getCanvas());
document.finishPage(page);

String targetPdf = "/sdcard/pdffromlayout.pdf";
File filePath;
filePath = new File(targetPdf);
try {
    document.writeTo(new FileOutputStream(filePath));

} catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(SchedaPaziente.this, "Something wrong: " + e.toString(), Toast.LENGTH_LONG).show();
}

// close the document
document.close();
Toast.makeText(SchedaPaziente.this, "PDF is created!!!", Toast.LENGTH_SHORT).show();

openGeneratedPDF();

【问题讨论】:

    标签: android android-layout checkbox


    【解决方案1】:

    试试:

    chM.setChecked(true);
    

    或者将 CheckBox 替换为 ToggleButton。

    【讨论】:

    • chM.setChecked(true) 不起作用。 ToggleButton 工作,但它不是完美的功能,因为我需要一个 CheckBox
    • @FullVisionDalton 如果它在您从布局中设置时有效,那么我建议您进行一些愚蠢的检查,如下所示: 1. 在包含 setChecked(true) 之前执行所有操作。 2. 然后启动新线程,它会做所有其他工作,但在这个线程内做一些 5 秒的睡眠。如果它有效,则意味着在将布局转换为 pdf 之前某些复选框动画尚未完成,因此实际上复选框已被选中,但似乎并未被选中。
    • 不幸的是,即使使用这种方法,CheckBoc 也不起作用。 chM.setChecked(true); try { Thread.sleep(5000); } catch (InterruptedException ex) { android.util.Log.d("YourApplicationName", ex.toString()); }
    • @FullVisionDalton 您需要启动新线程,而不仅仅是休眠,因为您现在正在 UI 线程中休眠,所以如果动画是这种情况,那么动画将无法继续,因为 UI 线程是被屏蔽了。
    • 我尝试像这样chM.setChecked(true); Thread thread = new Thread() { @Override public void run() { try { Thread.sleep(5000); } catch (InterruptedException e) { //nothing } } };thread.start(); 开始一个新线程首先我希望我做对了,如果我做对了它就行不通
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    相关资源
    最近更新 更多