Android findViewById() problem [duplicate]
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.
精彩评论