我有两个布局文件。第一个布局文件包含 TextView 中的一些数据,另一个布局包含一个空 TextView 。现在,当我在第一个布局中使用按钮时,我想将第一个布局的 TextView 数据传递到新的布局 TextView 。我该如何使用这个?提前致谢。
最佳答案
基本上你可以这样做,在按钮单击中,获取第二个布局的 View
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.secondlayout, parent, false);
并使用下面的语句来获取第二个 TextView 的ID
TextView text2=(TextView)row.findViewById(R.id.SecondTextView)
然后使用第一个 TextView 的 id 将第一个 TextView 中的文本获取到字符串中:
String s=text1.getText().toString();
然后将此字符串设置为第二个 TextView 。
text2.setText(s);
关于java - 安卓 : getting an item from a textview to another textview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6984234/