gallery.setAdapter中为什么老是说ImageAdapter是不可识别的类型

whatafuckinglongname 2011-05-16 12:44:25
我照着gallery的那个例子写的代码,但是在eclipse中,gallery.setAdapter的参数类型只有SpinnerAdapter。提示
ImageAdapter cannot be resovled to a type

package com.android.jiashie;

import android.app.Activity;
import android.os.Bundle;

//使用Gallery widget所用到的包
import android.content.Context;
import android.widget.Gallery;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.View;
import android.view.ViewGroup;

public class GalleryDemo extends Activity {
private TextView myText;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

myText = (TextView)findViewById(R.id.myText);

//Gallery ga = (Gallery)findViewById(R.id.myGallery);
((Gallery) findViewById(R.id.myGallery))
.setAdapter(new ImageAdaper(this));

}

public class ImageAdapter extends BaseAdapter{
private Context myContext;
//使用android.R.drawable中的图片作为图库源
private int[] myImageIDs = new int[] {
android.R.drawable.btn_minus,
android.R.drawable.btn_radio,
android.R.drawable.ic_lock_idle_alarm,
android.R.drawable.ic_menu_camera
};

//构造函数
public ImageAdapter(Context c)
{
this.myContext=c;

}
public int getCount()
{
// TODO Auto-generated method stub
return this.myImageIDs.length;
}

public Object getItem(int position)
{
// TODO Auto-generated method stub
return position;
}

public long getItemId(int position)
{
// TODO Auto-generated method stub
return position;
}

public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
//创建一个ImageView对象
ImageView iv = new ImageView(this.myContext);
iv.setImageResource(this.myImageIDs[position]);
iv.setScaleType(ImageView.ScaleType.FIT_XY);

//设置这个ImageView的宽高,单位为dip
iv.setLayoutParams(new Gallery.LayoutParams(120,120));
return iv;
}
//依据距离中央位置的偏移量,利用getScale返回views的大小(0.0f - 1.0f)
public float getScale(boolean focused,int offset) {
// formula: 1/(2^offset)
return Math.max(0, 1.0f/(float)Math.pow(2, Math.abs(offset)));
}

}
}

...全文
683 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hmg25 2011-05-16
  • 打赏
  • 举报
回复
阿,这样的错误我也遇到过,哈哈,以后要注意拉~
  • 打赏
  • 举报
回复
教训啊,以后遇到"cannot resovled to a type",先看有没有拼写错误..
lihongchuan 2011-05-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 whatafuckinglongname 的回复:]

晕了晕了晕了晕了

原来是单词拼写错误
ImageAdapter ==> ImageAdaper
[/Quote]

看了半天没看出来,呵呵
  • 打赏
  • 举报
回复
我像不像是来搞笑的??
  • 打赏
  • 举报
回复
晕了晕了晕了晕了

原来是单词拼写错误
ImageAdapter ==> ImageAdaper
  • 打赏
  • 举报
回复
((Gallery) findViewById(R.id.myGallery))
.setAdapter(new ImageAdaper(this));

eclipse在 setAdapter上提示public void setAdapter (SpinnerAdapter adapter)
参数类型是SpinnerAdapter啊?!!

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧