问题描述
我要显示按钮单击图像,但我有我的code三个错误。怎么了?
-
类名SequencerActivity
类型SequencerActivity必须实现继承的抽象方法
DialogInterface.OnClickListener.onClick(DialogInterface,INT)
。 -
next.setOnClickListener(本);
在
setOnClickListener(View.OnClickListener)
在类型中查看方法不适用于参数(SequencerActivity)
-
的onClick(视图v)
方法的onClick(视图)
类型 SequencerActivity
必须覆盖或实现超类型的方法。
这里的code使这些错误:
公共类SequencerActivity扩展活动实现OnClickListener
{
私人诠释imageCounter = 0;
私人ImageView的ImageLoader的;
私人INT []图像列表= {R.drawable.f03,R.drawable.f04,R.drawable.f05,R.drawable.f06};
@覆盖
公共无效的onCreate(包savedInstanceState)
{
的setContentView(R.layout.main); //这个是所有图像视图的公用父布局
super.onCreate(savedInstanceState);
/*requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); * /
// INT此搜索= R.drawable.image_w_lbl_0;
ImageLoader的=(ImageView的)findViewById(R.id.imageLoader);
//imageLoader.setImageResource(image1);
按钮旁边=(按钮)findViewById(R.id.next);
按钮回到=(按钮)findViewById(R.id.back);
next.setOnClickListener(本);
back.setOnClickListener(本);
back.setEnabled(假);
//显示默认的图像
this.loadImage(图像列表[imageCounter]);
}
@覆盖
公共无效的onClick(视图v)
{
INT的ImagePath = 0;
// TODO自动生成方法存根
开关(v.getId())
{
案例R.id.next:
Log.i(标记,标记);
如果(imageCounter< imageList.length)
{
imageCounter ++;
的ImagePath =图像列表[imageCounter]
如果(imageCounter ==(imageList.length)-1)
{
{
接下来的ImageButton =(的ImageButton)findViewById(R.id.next);
next.setEnabled(假);
}
}
其他
{
的ImageButton回=(的ImageButton)findViewById(R.id.back);
back.setEnabled(真正的);
}
}
打破;
案例R.id.back:
如果(imageCounter大于0)
{
imageCounter--;
的ImagePath =图像列表[imageCounter]
如果(imageCounter == 0)
{
的ImageButton回=(的ImageButton)findViewById(R.id.back);
back.setEnabled(假);
}
其他
{
接下来的ImageButton =(的ImageButton)findViewById(R.id.next);
next.setEnabled(真正的);
}
}
打破;
}
this.loadImage(的ImagePath);
}
私人无效的LoadImage(INT的ImagePath)
{
imageLoader.setImageResource(的ImagePath);
}
}
在 OnClickListener
您实现是不正确的,尝试实施View.OnClickListener而不是DialogInterface.OnClickListener。
您可以看到,在您的导入
进口View.OnClickListener
进口DialogInterface.OnClickListener
I want to display an image on button click, but I have three errors in my code. What's wrong?
class name "SequencerActivity"
The type SequencerActivity must implement the inherited abstract method
DialogInterface.OnClickListener.onClick(DialogInterface, int)
.next.setOnClickListener(this);
The method
setOnClickListener(View.OnClickListener)
in the type View is not applicable for the arguments(SequencerActivity)
.onClick(View v)
The method onClick(View)
of type SequencerActivity
must override or implement a supertype method.
Here's the code giving those errors:
public class SequencerActivity extends Activity implements OnClickListener
{
private int imageCounter = 0;
private ImageView imageLoader;
private int[] imageList = {R.drawable.f03, R.drawable.f04, R.drawable.f05, R.drawable.f06};
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.main);//this one is the common parent layout for all image views
super.onCreate(savedInstanceState);
/*requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
//int image1 = R.drawable.image_w_lbl_0;
imageLoader = (ImageView) findViewById(R.id.imageLoader);
//imageLoader.setImageResource(image1);
Button next = (Button) findViewById(R.id.next);
Button back = (Button) findViewById(R.id.back);
next.setOnClickListener(this);
back.setOnClickListener(this);
back.setEnabled(false);
//show the default image
this.loadImage(imageList[imageCounter]);
}
@Override
public void onClick(View v)
{
int imagePath = 0;
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.next:
Log.i("Tag","tag");
if(imageCounter < imageList.length)
{
imageCounter++;
imagePath = imageList[imageCounter];
if (imageCounter==(imageList.length)-1)
{
{
ImageButton next=(ImageButton)findViewById(R.id.next);
next.setEnabled(false);
}
}
else
{
ImageButton back=(ImageButton)findViewById(R.id.back);
back.setEnabled(true);
}
}
break;
case R.id.back:
if(imageCounter > 0)
{
imageCounter--;
imagePath = imageList[imageCounter];
if (imageCounter==0)
{
ImageButton back=(ImageButton)findViewById(R.id.back);
back.setEnabled(false);
}
else
{
ImageButton next=(ImageButton)findViewById(R.id.next);
next.setEnabled(true);
}
}
break;
}
this.loadImage(imagePath);
}
private void loadImage(int imagePath)
{
imageLoader.setImageResource(imagePath);
}
}
The OnClickListener
that you implement is not correct,try to implement View.OnClickListener and not DialogInterface.OnClickListener.
You can see that in your import
import View.OnClickListener
instead of
import DialogInterface.OnClickListener
这篇关于setOnClickListener(View.OnClickListener)在类型视图不适用于自变量(SequencerActivity)back.setOnClickListener(本);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!