import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.*;
import android.view.View.OnClickListener;
public class costom extends Activity implements OnclickListener{
public void onClick(View v){
switch (v.getId()) {
case R.id.button:
Intent i = new Intent(this, Nearbyhome.class);
startActivity(i);
break;}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View Button = findViewById(R.id.button);
Button.setOnClickListener(this);
}
}
显示问题“类型View中的方法setOnClickListener(View.OnClickListener)不适用于参数(costom)”
答案 0 :(得分:3)
有一个错字,OnclickListener,它应该是OnClickListener, 您可能没有导入软件包,如果您正在使用eclipse,请按ctrl + shift + o。
答案 1 :(得分:0)
public class costom extends Activity {
private MyOnCLickListener implements View.OnClickListener() {
public void onClick(View v){
switch (v.getId()) {
case R.id.button:
Intent i = new Intent(costom.this, Nearbyhome.class);
startActivity(i);
break;
}
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View Button = findViewById(R.id.button);
Button.setOnClickListener(new MyOnClickListener());
}
}
Java风格大会建议你用第一个大写字母命名你的班级为'Custom'而不是'costom'
答案 2 :(得分:0)
我不是世界上最好的Android程序员,但刚刚完成我的第一个Android应用程序的编写,我可能会按照以下方式进行操作,
public class Mainscreen extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//Sets where the image view is located
final Button Wordsearch_button = (Button) findViewById(R.id.Wordsearch_button);//Declares the usage of a button
Wordsearch_button.setOnClickListener(new OnClickListener() {//waits for the button click
public void onClick(View v) {
Intent next1 = new Intent();//when clicked it goes to the new intent i.e the java code Wordsearch_Action
next1.setClassName("android.solver", "android.solver.Solution2");
next1.putExtra("message_variable", "message");
startActivity(next1); //starts the new intent
}
});
}
希望能帮助您解决问题。