在两个单独的布局文件中引用 TextView @id?
有没有办法在单独的布局上创建 TextView 实例?我创建了一个包含 x 个对象的 ExpandableListView。我还想展示折叠组中的一个孩子。我意识到我可以在代码中进行设置,但是如果我可以多次指向相同的 id R.id.dscItem ,则会更容易、更清晰。
我尝试将“@+id/dscItem”中的 + 删除,使其成为“@id/dscItem”,但效果不大。难道我只能指向这个id一次吗!?
SimpleExpandableListAdapter mAdapter = new SimpleExpandableListAdapter(
this, createGroup(), R.layout.exprow, R.layout.row,
new String[] { Items.ITEMS_ITEM }, new int[] { R.id.txtItem },
createChildren(), R.layout.exprow, new String[] {
Items.ITEMS_DESC, Items.ITEMS_MANU },
new int[] { R.id.dscItem, R.id.manuItem });
XML 布局 1:
></TextView>
<TextView
android:text="Description"
android:id="@id/dscItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:textSize="15dip"
></TextView>
XML 布局 2
<TextView
android:text="Description"
android:id="@+id/dscItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#994020"
android:layout_gravity="right"
></TextView>
Is there a way to create an instance of a TextView on a separate layout? I have created an ExpandableListView with x number of objects. I would like to display one of the children in the collapsed group as well. I realize I could set up in the code, however it would be much easier, and much cleaner if I could just point to the same id R.id.dscItem multiple times.
I have tried dropping the + in "@+id/dscItem"so that it was "@id/dscItem" but it didn't do much. Is it true that I can only point to this id once!?
SimpleExpandableListAdapter mAdapter = new SimpleExpandableListAdapter(
this, createGroup(), R.layout.exprow, R.layout.row,
new String[] { Items.ITEMS_ITEM }, new int[] { R.id.txtItem },
createChildren(), R.layout.exprow, new String[] {
Items.ITEMS_DESC, Items.ITEMS_MANU },
new int[] { R.id.dscItem, R.id.manuItem });
XML layout 1:
></TextView>
<TextView
android:text="Description"
android:id="@id/dscItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:textSize="15dip"
></TextView>
XML layout 2
<TextView
android:text="Description"
android:id="@+id/dscItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#994020"
android:layout_gravity="right"
></TextView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在单独的布局中创建一个文本视图,并通过 xml 中的布局合并或 java 代码中的布局 inflater 来使用它
http://developer.android.com/resources/articles/layout-tricks -merge.html
You can create a textview in a separate layout and use it by layout merge in xml or layout inflater in java code
http://developer.android.com/resources/articles/layout-tricks-merge.html