New to Java, using Eclipse. Except this error I also got some:
Description Resource Path Location Type The method onClick(View) of type new onClickListener
Try this
@Override
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
//Listeneři
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button1.setText("Správně.");
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button2.setText("COŽE!?");
change your button click listener to this
button1.setOnClickListener(new View.onClickListener() {}
button2.setOnClickListener(new View.onClickListener() {}
// replace this code
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button2.setText("COŽE!?");
In the button2.setOnClickListener
method change
new onClickListener()
to
new OnClickListener()
Try this:
Button button1 ,button2;
@Override
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button1.setText("xyz");
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button2.setText("abc");
}
});
}