내 레이아웃에 표시 데이터를로드하는 데 ViewStubs
을 사용하고 있습니다. 을 사용하여 레이아웃 구성 요소를 바인딩하기 때문에 개별 viewstub 레이아웃의 구성 요소를 보유하는 맞춤 클래스가 있습니다. 예를 들어 이러한 뷰 스텁은 다음과 같습니다.ViewStub에 null이 아닌 ViewGroup 뷰가 있어야합니다.
public class FeaturedContentView {
@BindView(R.id.art)
ImageView art;
@BindView(R.id.shade)
View shade;
@BindView(R.id.title)
TextView featuredTitle;
@BindView(R.id.performer)
TextView performer;
@BindView(R.id.featured_title)
KerningTextView featuredText;
@BindView(R.id.play_button)
Button play;
@BindView(R.id.shareText)
TextView shareText;
@BindView(R.id.addToFavorites)
ImageView addToFavs;
FeaturedContentView(View view) {
ButterKnife.bind(this, view);
}
}
이 같은 레이아웃 팽창 : 다음과 같이
<ViewStub
android:id="@+id/featuredContentStub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/featuredContent"
android:layout="@layout/featured_content" />
@layout/featured_content
구성 요소를 처리하는 클래스입니다 위의 방법에서 두 개의 서로 다른 장소에서라고
if (viewstub != null) {
View view = viewstub.inflate();
featuredContentView = new FeaturedContentView(view);
}
을 내 파편. 첫 번째 시간은 정확하게 팽창하지만 두 번째는 java.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent
입니다.
어떻게 이런 상황을 처리 할 수 있습니까?
전체 조각 코드를 게시 할 수 있습니까, 나는 당신의'viewstub.inflate()'에 의심의 여지가 있습니다. –