我照着gallery的那个例子写的代码,但是在eclipse中,gallery.setAdapter的参数类型只有SpinnerAdapter。提示
ImageAdapter cannot be resovled to a typepackage 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)));
}
}
}
ImageAdapter cannot be resovled to a typepackage 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)));
}
}
}
解决方案 »
- 各位路过的神仙佛祖们,悟空有一问题实在不解,恳求神仙们赐教一二。想用这个setBackgroundResource引用背景的XML文件,无效果啊。
- 求android手机类似于QQ安全管家或者360安全卫士的开源软件
- Android工程怎么导入 java.awt.Dimension 类?
- QQ游戏大厅“模块式安装”原理?(手机QQ游戏大厅Android版发布 引入模块式安装)
- 有没有办法动态设置应用图标?
- listview下拉刷新,下拉的时候很卡,一钝一钝的
- 为什么animation没有set方法设置属性?
- ListView和ActivityGroup共同使用报空指针异常
- 图片圆角问题
- MediaPlayer的seekto方法怎么不能用了?
- tomcat问题
- 关于c程序移植到Android平台上的问题
.setAdapter(new ImageAdaper(this));eclipse在 setAdapter上提示public void setAdapter (SpinnerAdapter adapter)
参数类型是SpinnerAdapter啊?!!
ImageAdapter ==> ImageAdaper