stuck with a problem
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) {
开发者_如何学JAVA super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View Button = findViewById(R.id.button);
Button.setOnClickListener(this);
}
}
is showing a problem "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (costom)"
There is a typo , OnclickListener , it should be OnClickListener , You might not have imported the packages , press ctrl+shift+o if you are using eclipse.
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());
}
}
And Java Style Convention advises you name your clasess with first capital letter as 'Costom' instead of 'costom'
I am not the worlds best Android programmer but have just finished writing my first Android app, I would potentially look at doing it as follows,
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
}
});
}
Hope that helps you solving your problem.
精彩评论