Reputation: 11
Hi I can't seem to build this.. It states that it cannot resolve the OnClickListener
. The onClick action is performed the back button that goes to the main activity.
Button bnCompute = (Button) this.findViewById(R.id.bnCompute);
bnCompute.setOnClickListener(new View.OnClickListener());
{
@Override
public void onClick (View view){
Toast.makeText(MainActivity.this, "You Compute All!", Toast.LENGTH_LONG).show();
EditText etBeauty = (EditText) MainActivity.this.findViewById(R.id.etBeauty);
EditText etBody = (EditText) MainActivity.this.findViewById(R.id.etBody);
EditText etIntelligence = (EditText) MainActivity.this.findViewById(R.id.etIntelligence);
int total = Integer.parseInt(String.valueOf(etBeauty.getText())) + Integer.parseInt(String.valueOf(etBody.getText()))
+ Integer.parseInt(String.valueOf(etIntelligence.getText()));
Intent actSummary = new Intent(MainActivity.this, Score.class);
actSummary.putExtra("total", Integer.toString(total));
MainActivity.this.startActivity(actSummary);
}
}
Upvotes: 0
Views: 216
Reputation: 2023
You have implemented onClick
outside the scope of listener.
It should be something like this below :
Button button = (Button) findViewById(R.id.button1);
//Your mistake is on this line.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
}
});
Upvotes: 1