널을 뷰 루트로 전달하지 마십시오 (팽창 된 레이아웃의 루트 요소에서 레이아웃 매개 변수를 해결해야 함)
루트 스튜디오에 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;
}
}
대신에
convertView = infalInflater.inflate(R.layout.list_item, null);
하다
convertView = infalInflater.inflate(R.layout.list_item, parent, false);
주어진 부모와 함께 팽창 시키지만 부모에게 첨부하지는 않습니다.
에 대한 좋은 기사를 찾았습니다 LayoutInflater
. 저자는 방법의 모든 버전이 어떻게 inflate
작동 하는지 설명 ListView
하고AlertDialog
http://www.doubleencore.com/2013/05/layout-inflation-as-intended/
업데이트 # 1.
이 답변은 최근에 나에게도 도움이되었습니다. https://stackoverflow.com/a/5027921/1065835
Here ya go, for some reason using View.inflate instead of inflating from a layoutinflater makes the lint error disappear. Thought I'd post this here since this thread is at the top of the Google Search...
view = View.inflate(context,R.layout.custom_layout,null);
When you really don't have any parent
(for example creating view for AlertDialog
), you have no other way than passing null
. So do this to avoid warning:
final ViewGroup nullParent = null;
convertView = layoutInflater.inflate(R.layout.list_item, nullParent);
A nice information I found while looking for a way to solve this.According to Dave Smith,
Layout inflation is the term used within the context of Android to indicate when an XML layout resource is parsed and converted into a hierarchy of View objects.
The ViewGroup
been asked for here as part of the inflate method parameters is used to inherit higher level styling.While passing null can seem harmless, it can actually cause serious problems for your app later on. Read more about this here.
For AlertDialog
bellow code can be used
convertView = layoutInflater.inflate(R.layout.list_item, findViewById(android.R.id.content), false);
'Programing' 카테고리의 다른 글
각도 및 타이프 스크립트 : 이름을 찾을 수 없습니다 (0) | 2020.04.28 |
---|---|
임시 디렉토리를 만드는 방법은 무엇입니까? (0) | 2020.04.28 |
주어진 이름과 일치하는 리소스를 찾을 수 없습니다 : attr 'android : keyboardNavigationCluster'. (0) | 2020.04.28 |
bash에서 "group by"를 시뮬레이션하는 가장 좋은 방법은 무엇입니까? (0) | 2020.04.28 |
일반 사전에 대소 문자를 구분하지 않는 액세스 (0) | 2020.04.28 |