Button onClick error…Could not find a method

后端 未结 2 1948
我在风中等你
我在风中等你 2020-12-22 12:33

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

2条回答
  •  不知归路
    2020-12-22 12:52

    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"
    

提交回复
热议问题