LayoutInflaterを使用して親レイアウトを膨らませた後、ImageViewのNullReferenceExcpetionで問題が発生します。以下のレイアウトXMLでわかるように、2つのTextViewと1つのImageViewがあります。両方のTextViewを問題なく参照できますが、ImageViewは参照できません。
膨らんだレイアウトの子ビューのプロパティにドリルダウンすると、両方のTextViewのmIDプロパティが正しいことがわかりますが、ImageViewのmIDは-1です。
ImageViewだけがNULLとして表示される理由を誰かが知っているでしょうか?ばかげていると思いますが、理解できません。また、レイアウトXMLファイルを再作成したり、プロジェクトをクリーンアップしたりしました。
前もって感謝します!!
レイアウトXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:layout_width="120px"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/weather_forecast_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textStyle="bold"/>
<ImageView android:id="@+id/weather_forecast_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<TextView android:id="@+id/weather_forecast_temps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
コード:
mForecastItem = (LinearLayout)View.inflate(WeatherLookup.this, R.layout.weather_forecast_item, null);
((ImageView)mForecastItem.findViewById(R.id.weather_forecast_icon))
.setImageDrawable(getResources().getDrawable(R.drawable.weather_sunny));
((TextView)mForecastItem.findViewById(R.id.weather_forecast_day))
.setText(forecast.DayOfWeek);
((TextView)mForecastItem.findViewById(R.id.weather_forecast_temps))
.setText(forecast.High + "\u2109 / " + forecast.Low + "\u2109");