has*_*ash 218 android warnings android-layout layout-inflater
为root studio传递null给了我这个警告:
避免将null作为视图根传递(需要解析膨胀布局的根元素上的布局参数)
它显示为空值getGroupView.请帮忙.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
super();
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
Coe*_*ect 346
而不是做
convertView = infalInflater.inflate(R.layout.list_item, null);
Run Code Online (Sandbox Code Playgroud)
做
convertView = infalInflater.inflate(R.layout.list_item, parent, false);
Run Code Online (Sandbox Code Playgroud)
它将使用给定的父级对其进行膨胀,但不会将其附加到父级.
Mak*_*iev 51
我发现了一篇很好的文章LayoutInflater.作者解释了该inflate方法的所有版本如何工作并给出了ListView和的例子AlertDialog
http://www.doubleencore.com/2013/05/layout-inflation-as-intended/
更新#1.
这个答案最近对我有帮助. /sf/answers/351954501/
Thu*_*ick 31
在这里,由于某种原因,使用View.inflate而不是从layoutinflater进行膨胀会使lint错误消失.以为我会在这里发布这个帖子,因为这个帖子位于Google搜索的顶部...
view = View.inflate(context,R.layout.custom_layout,null);
Run Code Online (Sandbox Code Playgroud)
Mou*_*usa 28
如果你真的没有parent(例如创建视图AlertDialog),除了传递之外别无他法null.所以这样做是为了避免警告:
final ViewGroup nullParent = null;
convertView = layoutInflater.inflate(R.layout.list_item, nullParent);
Run Code Online (Sandbox Code Playgroud)
对于AlertDialog波纹管代码可以使用
convertView = layoutInflater.inflate(R.layout.list_item, findViewById(android.R.id.content), false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
78089 次 |
| 最近记录: |