gpt4 book ai didi

android - 如何在不同的布局中获取 id

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:01 25 4
gpt4 key购买 nike

当我使用 findVewById 时,我在 single_item.xml 中有 id "@+id/call" (布局 setcontextview (R.layout.main)) .app crash .how to fix the error

最佳答案

如果你想访问另一个布局(不是 Activity 布局)中的 View ,那么你可以扩展你想使用的布局并以这种方式访问​​它。

例子:

View inflatedView = getLayoutInflater().inflate(R.layout.other_layout, null);
TextView text = (TextView) inflatedView.findViewById(R.id.text_view);
text.setText("Hello!");

可以找到有关膨胀布局的更多信息here .

关于android - 如何在不同的布局中获取 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4211189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com