diadiaki
diadiaki

Reputation: 33

Error: Cannot resolve symbol 'OnClickListener'

in the following class there is one error with the message "Cannot resolve symbol 'OnClickListener'. I've already read some of the answers in similar questions but I couldn't fix it. Thank you in advance!

package dmst.allamoda;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
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 android.widget.Toast;

public class Home extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Button btnSimple = (Button) findViewById(R.id.home);
    btnSimple.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent intent1 = new Intent(v.getContext(), Home.class);
            startActivity(intent1);
        }
    });
}
}

Upvotes: 1

Views: 3047

Answers (1)

Andrew Brooke
Andrew Brooke

Reputation: 12173

You need to use View.OnClickListener

btnSimple.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent intent1 = new Intent(v.getContext(), Home.class);
        startActivity(intent1);
    }
});

If it is still not recognized, you need to use the following import

import android.view.View.OnClickListener;

Moreover, if you hover over the error in Android Studio, it will give you some additional information (in this case, it should offer to import it for you)

Upvotes: 4

Related Questions