Re: [android-developers] android how to use same layout in the other layout files.
As stated by Steve.
-- 1) Give the TextView an id. This can be in the included file itself (and hence always the same),
or you can set the id for the included part in each <include> tag if you want (if the TextView is the only thing included and the root view in the included layout).
In the two parts of code that use each of the 2 included versions of the view:
2) Find the TextView by it's ID
TextView tv = (TextView)findViewById(R.id.text_view_id)
NOTE: If they are both in the same View hierarchy, with the same id, you can look for each one in only a part of it using View.findViewById()
TextView tv1 = (TextView)textViewAncestor1.findViewById(R.id.text_view_id)
TextView tv2 = (TextView)textViewAncestor2.findViewById(R.id.text_view_id)
3) Then set the text from code:
tv1.setText("hello"):
tv2.setText(hello2");
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home