Button Onclick Error...could Not Find A Method
I can't seem to start a new Activity from my Button, I have searched here for answers, but can't seem to resolve the problem. I hope someone has an easy solution. Thanks In advance
Solution 1:
The problem is in your method signature
publicvoidopenSearch(){
it should have one, and only one param, which is a View
.
Change it to
publicvoidopenSearch(View v){
v
obviously can be anything you want it to be but you should make it something meaningful like v
, view
, etc...
In order for this to work, the method must be public and accept a View as its only parameter.
See this answer for a more detailed description of adding Buttons
and OnClick
Solution 2:
First make a reference to your button
search = (Button) findViewById(R.id.btnStartSearch);
Then implement the onClick listner for the button as below
search.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
IntentopenSearchIntent=newIntent(MainActivity.this, StartSearch.class);
startActivity(openSearchIntent)
}
});
Make sure you remove this line from your XML file
android:onClick="openSearch"
Post a Comment for "Button Onclick Error...could Not Find A Method"