[英]Unable resovle Inflate
So I am trying to inflate a layout in my activity but I keep getting this error "Cannot resolve method 'inflate(int, android.view.ViewGroup, null)'"所以我试图在我的活动中扩大布局,但我不断收到这个错误“无法解析方法'inflate(int,android.view.ViewGroup,null)'”
Here my Code:这是我的代码:
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list,parent,null));
}
did i missing something?我错过了什么吗?
You can use this way.您可以使用这种方式。
First import the fragment.首先导入片段。
import androidx.fragment.app.DialogFragment;
then extand from DialogFragment like this extends DialogFragment
然后从 DialogFragment 像这样
extends DialogFragment
and then overide the onCreateView
然后覆盖
onCreateView
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.YOUF-RRAGMENT-NAME, container, false);
//to access xml elements you use view.findviewbyid ...
return view;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.