티스토리 뷰
반응형
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)
null을 뷰 루트로 전달하지 않도록 합니다(inflated 된 레이아웃의 루트 요소에서 레이아웃 매개 변수를 확인해야 함).
문제 내용
Passing null for root studio gives me this warning:
null을 전달하면 다음과 같은 경고가 표시됩니다.
Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)
null을 뷰 루트로 전달하지 않도록 합니다(inflated 된 레이아웃의 루트 요소에서 레이아웃 매개 변수를 확인해야 함).
It is showing a null value in getGroupView
. Please help.
getGroupView에 null 값이 표시됩니다. 제발 도와주세요.
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;
}
}
높은 점수를 받은 Solution
Instead of doing
아래 대신에
convertView = infalInflater.inflate(R.layout.list_item, null);
do
아래를 적용하세요.
convertView = infalInflater.inflate(R.layout.list_item, parent, false);
It will inflate it with the given parent, but won't attach it to the parent.
지정된 부모 뷰를 사용하여 inflate하지만, 부모 뷰에 붙이지는 않습니다.
가장 최근 달린 Solution
For AlertDialog
bellow code can be used
AlertDialog의 경우 아래 코드를 사용할 수 있습니다.
convertView = layoutInflater.inflate(R.layout.list_item, findViewById(android.R.id.content), false);
출처 : https://stackoverflow.com/questions/24832497/avoid-passing-null-as-the-view-root-need-to-resolve-layout-parameters-on-the-in
반응형
'개발 > 안드로이드' 카테고리의 다른 글
AlertDialog 테마 변경하기 (0) | 2022.12.16 |
---|---|
안드로이드에서 투명한 액티비티 만들기 (0) | 2022.12.14 |
동적(코드)으로 뷰에 dp단위로 마진 적용하기 (0) | 2022.12.13 |
다른 패캐지의 디폴트 액티비티 실행하기 (0) | 2022.12.13 |
View의 GONE과 INVISIBLE의 차이 (0) | 2022.12.13 |
댓글
공지사항
최근에 올라온 글