当我使用 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/