gpt4 book ai didi

android - 在自定义对话框的 TextView 中设置文本

转载 作者:太空狗 更新时间:2023-10-29 15:45:37 25 4
gpt4 key购买 nike

我想以编程方式设置包含在自定义对话框中的 TextView 中的文本,以便我可以使用 Html.fromHtml。我应该在哪个函数中调用 setText?我试过在 onCreateDialog 中这样做,但这实际上并没有改变文本。

public class InfoDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.infodialog, null));

TextView textView = (TextView) getActivity().findViewById(R.id.info);
textView.setText(Html.fromHtml("<h1>Text has been correctly set</h1>"));
...

最佳答案

试试这个:

View content =  inflater.inflate(R.layout.infodialog, null);   
builder.setView(content);
TextView textView = (TextView) content.findViewById(R.id.info);

关于android - 在自定义对话框的 TextView 中设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959101/

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