How to implement OnClickListener on Android

前端 未结 5 669
眼角桃花
眼角桃花 2021-01-06 16:26

I learn from

http://developer.android.com/reference/android/widget/Button.html

that \"instead of applying an OnClickListener to the button

5条回答
  •  梦毁少年i
    2021-01-06 16:56

    public class start extends Activity implements View.OnClickListener { Button bSMS;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        bSMS = (Button) findViewById(R.id.button);
    
    
        bSMS.setOnClickListener(this);
    
    }
    
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
    
        switch (arg0.getId()) {
    
            case R.id.button:        //"Block SMSs" button pressed
                startActivity(new Intent(this,secret_main.class));
                break;
    
        }
    }
    

    }

提交回复
热议问题