开发者

Android: Cannot cast from View to Gallery

I'd like to make a Gallery in android. In order to set the adapter in need to get the gallery which I defined in my xml file. Im doing that as: Gallery g = (Gallery) findViewById(R.id.gallery1); But with this code I can't compile my project, since I get the Error "Cannot cast from View to Gallery". My xml-file looks like this: "

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://开发者_开发问答schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
 <Gallery android:id="@+id/gallery1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:gravity="bottom"
 />
</LinearLayout>

Anybody knows how to solve my problem? Thanks a lot


Your code looks fine. Check if you have the correct import for Gallery

import android.widget.Gallery;


I think you just created the Object instance for Gallery. Gallery is a AdapterView. So you must set Adapter for the Content. please check this sample

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜