gpt4 book ai didi

java - Activity 和 createpdf 函数之间的依赖关系

转载 作者:行者123 更新时间:2023-12-02 06:22:13 25 4
gpt4 key购买 nike

我想在 Android 应用程序中创建一些 pdf 文件。
我找到了一个教程,效果很好,但是......
我在 Activity 中使用自己的函数 createPDF()。
我的问题是:如何使用内部 createPDF() 函数(例如 TextView tv1)来填充段落?

一些示例代码

public class GenPDF extends Activity {

TextView tv1;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.genpdf);
createPDF();
}

public void createPDF()
{
Document doc = new Document();
Paragraph p1 = new Paragraph(//my text from textview goes here//);
doc.add(p1);
}

举个例子,我如何将 tv1(这是一个 TextView)中的一些文本放入段落 p1?

最佳答案

像这样简单的东西应该适合你。以后,请阅读 TextView 的文档,因为它很好地描述了如何获取其文本内容。

TextView textView = (TextView) findViewById(R.id.tv1);
String textViewContents = textView.getText();
Paragraph p1 = new Paragraph(textViewContents);
doc.add(p1);

关于java - Activity 和 createpdf 函数之间的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20911705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com