Android更改textview内容

时间:2015-11-07 22:25:37

标签: java android xml textview android-inflate

您好我试图更改另一个xml的textview的内容。 不幸的是它不起作用,我的代码看起来像这样:

    View inflatedView = getLayoutInflater().inflate(R.layout.fragment_main, null);
    TextView testView= (TextView) inflatedView.findViewById(R.id.section_label);
    TextView test = (TextView) inflatedView.findViewById((R.id.testext));
    testView.setText("adasd");
    test.setText("adjhsajdH");

有没有人知道解决方案。

2 个答案:

答案 0 :(得分:0)

当您为布局充气时,它会创建一个新布局。这意味着您的第一行代码不会检索片段的布局,而是创建一个新的代码。 那就是为什么你没有在片段视图中看到变化。

如果要更改片段显示的值,请创建一个新方法,在该方法中将在内部执行作业的片段。

答案 1 :(得分:0)

试试这个。从父视图中删除旧布局。

parentView.removeView(urtextview)

然后添加刚编辑的新文本视图

parentView.add(urTextView)
相关问题