【问题标题】:Issues while inflating xml in ANDROID在 ANDROID 中膨胀 xml 时出现问题
【发布时间】:2013-03-20 06:22:02
【问题描述】:

我在膨胀的 xml 中有一个按钮,我想获取它的 xml id。请帮我做一些事情....... 我已经膨胀了这样的东西。

RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.relative);

//创建一个视图来膨胀layout_item(之前创建的带有textView的xml)

view = getLayoutInflater().inflate(R.layout.inflate, mainLayout,false);

//将视图添加到主布局中

mainLayout.addView(view);

【问题讨论】:

  • 你的问题是什么?您是否需要从膨胀的布局中获取布局或视图?你可以使用 view.findViewById(R.id.yourLayoutId);
  • @kavya 你的问题是什么?
  • 问题在哪里..?
  • @kavya 你想要任何子视图到相对布局!!

标签: android xml inflate


【解决方案1】:

检查此代码

RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id. relative);
View childLayout = getLayoutInflater().inflate(R.layout.child);
mainLayout.addView(childLayout);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多