开发者

Android findViewById() problem [duplicate]

This question already has answers here: 开发者_C百科 Closed 11 years ago.

Possible Duplicate:

Android Problem calling TextView from second layout file

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);

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

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);

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);

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

Thanks A


I'm quite new to Android so I am not sure, but I think this should work:

TextView textView = (TextView)View.inflate(this, R.layout.display_item, null);

"this" would be your Activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜