LoginSignup
7
4

More than 5 years have passed since last update.

【Android】Viewのinflate時にwarningが出る場合の対処法

Posted at

Viewをinflateする際、下記のように第2引数にnullを渡すとwarningが出る。

LayoutInflater.from(context).inflate(R.layout.hoge, null);

warningの内容は「rootViewにnull渡すと相応しいLayoutParamsが付けられんので、何か渡してちょ」という感じ。
なので、基本的にはnullじゃなくてちゃんと値を渡しましょー。

ActivityのContentViewをinflateで生成したい場合など、どうしてもnullしか渡せない時は下記で回避可能。

View.inflate(context, R.layout.hoge, null);

View.inflate()内部では上記と全く同じことをやっているが、メソッドが1枚噛むので呼び出し側ではwarningが出なくなる。

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4