[英]setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (SequencerActivity) back.setOnClickListener(this);
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)
. SequencerActivity类型必须实现继承的抽象方法
DialogInterface.OnClickListener.onClick(DialogInterface, int)
。
next.setOnClickListener(this);
The method setOnClickListener(View.OnClickListener)
in the type View is not applicable for the arguments (SequencerActivity)
. 类型View中的方法
setOnClickListener(View.OnClickListener)
不适用于参数(SequencerActivity)
。
onClick(View v)
The method onClick(View)
of type SequencerActivity
must override or implement a supertype method. SequencerActivity
类型的onClick(View)
方法必须覆盖或实现超类型方法。
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. 您实现的
OnClickListener
不正确,尝试实现View.OnClickListener而不是DialogInterface.OnClickListener。
You can see that in your import 您可以在导入中看到它
import View.OnClickListener
instead of 代替
import DialogInterface.OnClickListener
you need to import import android.view.View.OnClickListener;
你需要导入
import android.view.View.OnClickListener;
So your code look like 所以你的代码看起来像
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener{
// Your oncreate() and rest of all code
}
// you should have method as below
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.editText1) // just for instance
{
.. your onclick handle code
}
}
Still you are not able to resolve the error type import View.OnClickListener;
仍然无法解决错误类型
import View.OnClickListener;
then move the cursor on the View in import View.OnClickListener;
然后在
import View.OnClickListener;
的View上移动光标import View.OnClickListener;
It will open up pop-up then choose the Organize imports option. 它将打开弹出窗口,然后选择“组织导入”选项。
Use simply import View.OnClickListener;
使用简单
import View.OnClickListener;
at the top. 在顶部。
The OnClickListener
you're implementing is the wrong one. 您正在实现的
OnClickListener
是错误的。 It says it's DialogInterface.OnClickListener
, while you probably want View.OnClickListener
. 它说它是
DialogInterface.OnClickListener
,而你可能想要View.OnClickListener
。 You can correct that in the corresponding import
statement. 您可以在相应的
import
语句中更正它。
Just do only One thing. 只做一件事。 Use "import android.view.View.OnClickListener" statement at the top of the program.
在程序顶部使用“import android.view.View.OnClickListener”语句。
Do one thing 做一件事
remove import android.content.DialogInterface.OnClickListener; remove import android.content.DialogInterface.OnClickListener; and import android.View.View.OnClickListener
并导入android.View.View.OnClickListener
this will solve the problem 这样可以解决问题
Happy Coding 快乐的编码
实现View.view.onClickListener
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.