Я получаю сообщение об ошибке. Невозможно понять, как использовать дочерние представления в моем пользовательском представлении (относительная компоновка).Пользовательский макет с дочерними представлениями
<RelativeLayout >
<com.xxxxxx.FavouriteImageView
android:id="@+id/favorite_status"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:clickable="true" >
<ImageView
android:id="@+id/favourite_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/yellow_star"
android:clickable="false" />
<ProgressBar
android:id="@+id/favorite_spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:clickable="false" />
</com.xxxxxxxx.FavouriteImageView>
public class FavouriteImageView extends RelativeLayout{
ImageView star;
ProgressBar spinner;
boolean isFavorite;
Context context;
public FavouriteImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context= context;
findChildViews();}
public FavouriteImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context= context;
findChildViews();
}
public FavouriteImageView(Context context) {
super(context);
this.context= context;
findChildViews();}
private void findChildViews(){
star = (ImageView) findViewById(R.id.favourite_iv);
spinner = (ProgressBar) findViewById(R.id.favorite_spinner);
}
}
Проблема заключается в том, я продолжаю получать NPE, когда я когда-нибудь попробовать использовать star
или spinner
. Не знаю, как использовать представления для детей.
Они еще нет в конструкторе. Почему бы вам просто не назвать этот код в своей деятельности? – Simas