The class is not abstract and does not cancel the abstract onClick (View) method in OnClickListener

I am new to android development and trying to create an application to check if a given string is Palindrome or not. What is the problem with this code?

I am using Android Studio.

Error

The class is not abstract and does not cancel the onClick abstract method (View) in OnClickListener

package com.example.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.lang.String; import java.lang.StringBuffer; public class Alaukik extends AppCompatActivity implements View.OnClickListener { private View v; final TextView textView = (TextView) findViewById(R.id.textView2); final EditText editText = (EditText) findViewById(R.id.editText); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alaukik); final Button checkbutton = (Button) findViewById(R.id.button); checkbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String str = editText.getText().toString(); StringBuffer b = new StringBuffer(str); String reved = b.reverse().toString(); if (reved.equals(str)) { textView.setText("Palindrome"); } else { textView.setText("Not a Palindrome"); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_alaukik, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 
+5
source share
2 answers

You just need to override the onClick(View) method, add:

 @Override public void onClick(View view) { } 

But I see that you are not using this method anyway, since you are using setOnClickListener(new View.OnClickListener()); so you can simply remove the implements View.OnClickListener part without overriding the onClick method

+7
source
 mybutton.setOnClickListener( new Button.OnClickListener () { @Override // to override the method public void onClick(View view) { TextView mytext = (TextView) findViewById(R.id.mytext); mytext.setText("clicked now"); } } ); 
0
source

All Articles