Android的问题,从第二个布局文件调用的TextView [英] Android Problem calling TextView from second layout file

查看:209
本文介绍了Android的问题,从第二个布局文件调用的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们对我的活动主要布局XML文件R.layout.date_list_layout因为它是用来如下:

Hey guys the main layout xml file for my activity is R.layout.date_list_layout as it is used as follows

 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.date_list_layout);

不过,我想从这个同样的活动在另一个布局xml文件设置一个TextView文本R.layout.display_item

However I wish to set the text in a TextView from this same activity in another layout xml file R.layout.display_item

我知道,我通常会用下面的code,但是这是不工作的R.id.currency TextView的是不是在主R.layout.date_list_layout ....

I know I would usually use the code below but this is not working as the R.id.currency TextView is not in the main R.layout.date_list_layout....

TextView currency = (TextView) findViewById(R.id.currency);
currency.setText(cur);

据我所知,code下一行是不正确,但有没有办法写code类似的一行访问R.id.currency在R.layout.display_item XML或能不做什么?

I know the next line of code is incorrect but is there a way to write a similar line of code to access the R.id.currency in the R.layout.display_item xml or can this not be done?

TextView currency = (TextView) findViewById(R.layout.display_item/R.id.currency);
currency.setText(cur);

一些帮助真的会pciated AP $ P $,因为这有我猛然一惊的最后两天,我找不到任何解决方案的在线

Some help would really be appreciated as this has me boggled the last two days and I can't find any solution online

推荐答案

由于二TextView的是另一个布局的一部分,所以我们必须用

As Second TextView is the part of another layout so we have to used

 setContentView(R.layout.R.layout.display_item);

因此​​,对于第二个TextView的改变你code到

So for second TextView Change you code to

setContentView(R.layout.display_item);

TextView currency = (TextView) findViewById(R.layout.display_item/R.id.currency);

currency.setText(cur);

这篇关于Android的问题,从第二个布局文件调用的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆