Cannot Resolve OnClickListener android studio 1.3.2!

0 mohamed sayed · September 18, 2015
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends Activity implements View.OnclickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


}

// Any help?/

Post a Reply

Replies

Oldest  Newest  Rating
0 Casper Hollemans · September 18, 2015
I'm not such a expert in android but maybe I can help.

Did you import the package for it, not only implement?

for now that's my only guess it could be.

-Greets
0 mohamed sayed · September 18, 2015
@Casper yes, i did imported all the packages needed, but still not working.

-Thanks 
0 Martin Kalužík · September 18, 2015
Hi Mohamed,

I think what Android does not like is that lower case "c" in OnClickListener

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends Activity implements View.OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


}




Give it a try and let me know whether this helped :)
0 mohamed sayed · September 20, 2015
@Martin The main problem is that OnClickListener is not implemented from the view class it is implemented from the DialogInterface.
i really have no clue!
0 Gabriel James · September 28, 2015
keep trying u will find it out
0 Bob Kako · September 29, 2015
// I think you are missing this import...
import android.view.View.OnClickListener;

// and use capital C in OnClickListener
public class FirstActivity extends Activity implements OnClickListener {


You can also ditch the "implement OnClickListener" and do it inline.  Here is an example: 

Button BobButton = (Button)findViewById(R.id.BobButton);

BobButton.setOnClickListener(
     
    new Button.OnClickListener(){
       
       public void onClick(View v){
          TextView bobText = (TextView) findViewById(R.id.BobText);
           bobText.setText("Nice Button Push");

       }
    }
);
  • 1

Java / Android Development

107,275 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator