- Forum posts: 2
Dec 4, 2016, 3:25:07 PM via Website
Dec 4, 2016 3:25:07 PM via Website
Hello, I'm creating a button that will start a new activity but it gives me an error Cannot Resolve symbol OnClickListener
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.viewb);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, View.class));
}
});
Button b2 = (Button) findViewById(R.id.adminb);
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Admin.class));
}
});
}
}
I'm using the correct syntax but it still gives me errors
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.