私はそれの下にイメージビューを持つギャラリーを作成するチュートリアルに従ってきました。私がやりたいことは、ギャラリーを下に置き、イメージビューをその上に置くだけですが、XMLでそれらを切り替えると、ClassCastExceptionが表示されます。ここで ClassCastException(Gallery + ImageView)
はXMLです:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backrepeat"
android:orientation="vertical" >
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
非作業バージョンである
が、ImageViewの作品以上のギャラリーを置きます。ログから
:
01-26 22:20:13.673: E/AndroidRuntime(349): Caused by: java.lang.ClassCastException: android.widget.ImageView
01-26 22:20:13.673: E/AndroidRuntime(349): at com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36)
のonCreate:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(Photos.this));
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(mImageIds[0]);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
imgView.setImageResource(mImageIds[position]);
}
});
}
その他の役に立つコード:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
うんImageViewのは、上記で、ギャラリーは以下であれば、私も同じ問題を取得しています。 –
このコードを表示することもできますか:com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36) –
すでにあります。 –