zxh_33 2017-08-20 05:51 采纳率: 0%
浏览 2165

android studio中如何不使用setContentView而获取到xml中的控件

有xmlA,xmlB;MainActivity。Main中有xmlA的点击方法,要在用户点击xmlA时改变xmlB的内容,应该如何获取xmlB?

  • 写回答

3条回答 默认 最新

  • legendCoder 2017-08-20 06:03
    关注

    LayoutInflater layoutInflater = LayoutInflater.from(this);

    View layout = layoutInflater.inflate(R.layout.layout, null);

    通过这种方式加载view和setContentView不同。setContentView是直接加载到ui界面上,layoutInflater.inflate只获取你想要的view。

    评论

报告相同问题?