• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

setOnClickListener how to do it in Android Studio

am having a simple programmatic problem with my Android studio
the problem is that i can't type
Code:
btn.setOnClickListener (new View.OnClickListener()
){
[USER=1021285]@Override[/USER]
onClick(
//code here
)
}
can any cs student or fresh Graduate reply me with what needs to be said to android studio in order to execute that code i know the code but cant write it as it give me cannot resolve symbol 'setOnClickListener'
 
Last edited:
you are true it should be like so exactly but when i type btn.setOnClickListener it tells me cannot resolve symbol setOnClickListener my question is what is required to be done in order to type this snippet you typed
 
you are true it should be like so exactly but when i type btn.setOnClickListener it tells me cannot resolve symbol setOnClickListener my question is what is required to be done in order to type this snippet you typed

Did you create a layout for your button in the layout xml file for the activity it is in?
Did you define your button in java with the id of your button from the layout xml file like this...

Java:
Button btn = findViewById(R.id.YOUR_BUTTON_ID_HERE);

It's hard to help without seeing any code.
 
Code:
 Button bNext=(Button)findViewById(R.id.btn);
    bNext.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){

            )
this is the code am working on but can't recognize setOnClickListener and can't recognize Overrides also
 
Last edited:
Please post the whole class, including any import statements.
 
Back
Top Bottom