Issue
Idk what to do so basically i was creating a button which opens new activity on long press could u fix this?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
defineView();
handleIntent();
defineActionBar();
checkPermission();
button.setOnLongClickListener(new View.OnCLongClickListener() {
@Override
public void onLongClick(View v) {
openWebsite();
}
});
}
public void openWebsite() {
Intent intent = new Intent(this, Website.class);
startActivity(intent);
}
Solution
I guessed you have typed it manually. I found ..View.OnCLongClickListener()
.. which should be View.OnLongClickListener()
without 'C', you may try using the suggestion popping up while typing by the IDE
directly, it will reduce our typo mistake.
Another one, the method inside the LongClickListener
should be 'boolean' instead of 'void', which will return either TRUE
or FALSE
. True, means that your event will just be handled within that code, and no other events will be fired after this point, false otherwise.
I provided the code below, you may refer to it and try it out. Hope it works for you. :)
button.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
openWebsite();
return true;
}
});
Happy coding!! :D
Answered By - erwandy92
Answer Checked By - Mary Flores (JavaFixing Volunteer)