繁体   English   中英

android:从一个textview到另一个textview获取项目?

[英]android : getting an item from a textview to another textview?

我有两个布局文件。 第一个布局文件在textview中包含一些数据,另一个布局文件包含一个空的textview。 现在,当我在第一个布局中使用按钮时,我想将第一个布局的textview数据传递给新的布局textview。 我该如何使用呢? 提前致谢。

基本上你可以这样,点击按钮,获得第二个布局的视图

LayoutInflater inflater=getLayoutInflater();
            View  row=inflater.inflate(R.layout.secondlayout, parent, false);

并使用以下语句获取第二个textview的ID

TextView text2=(TextView)row.findViewById(R.id.SecondTextView)

然后使用第一个text的ID将第一个textview中的文本获取到String中:

String s=text1.getText().toString();

然后将此String设置为2nd textview。

text2.setText(s);

如果是,则textview2是第二个布局中的textview。

//to get data from text view of first layout use the following code
LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = inflater.inflate(R.layout.layout1, null);

TextView tv1 = (TextView) vi.findViewById(R.id.textview1);
// to set of first textview in second textview
textview2.setText(tv1.getText().toString

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM