Button onClick error…Could not find a method

感情迁移 提交于 2019-11-29 17:23:10
codeMagic

The problem is in your method signature

public void openSearch(){

it should have one, and only one param, which is a View.

Change it to

public void openSearch(View v){

v obviously can be anything you want it to be but you should make it something meaningful like v, view, etc...

From the Docs

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

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(new OnClickListener() {

        @Override
        public void onClick(View v) {

             Intent openSearchIntent = new Intent(MainActivity.this, StartSearch.class);
             startActivity(openSearchIntent)
        }
    });

Make sure you remove this line from your XML file

 android:onClick="openSearch"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!