package com.example.applecounter;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.R.integer;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.transition.Fade;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
//Here start my code //
public class Play extends Activity implements OnClickListener {
int counter=0;
private MediaPlayer mplayer;
private TextView txt;
private static final int[] idArray = { R.id.imageButton1, R.id.imageButton2 };
private ImageButton[] bt = new ImageButton[10];
// This is oncreate() which works fine but the code for make an ImageButton array is not working and got the error.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
LinearLayout ll = new LinearLayout(context);
for (int i = 0; i < idArray.length; i++) {
final int b = i;
bt[b] = (ImageButton) findViewById(idArray[b]);
bt[b].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}
}
当我导入ViewOnClickListener时,我得到了您将在下面找到的错误。 在这里你有我的代码我得到了错误
Play类型必须实现继承的抽象方法 View.OnClickListener.onClick(查看)
答案 0 :(得分:1)
你有
public class Play extends Activity implements OnClickListener {
您需要覆盖
@Override
public void onClick(View V)
{
}
由于您有一个匿名内部类,因此不需要implements OnClickListener
答案 1 :(得分:0)
而不是将onClick方法--inide-放在onCreate上,
1)在你的onCreate状态下你的btn_whatEver.setOnClickListener(this);
2)覆盖public void onClick(View V)
-outside-你的onCreate方法,并使用Switch调用各种按钮。