按下按钮后,我可以运行以下代码吗?
是否正确?
我有此代码
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int item_id = item.getItemId();
if (item_id == android.R.id.home) {
super.onBackPressed();
} else if (item_id == R.id.action_checkout) {
if (adapter.getItemCount() > 0) {
Intent intent = new Intent(ActivityShoppingCart.this, ActivityCheckout.class);
startActivity(intent);
} else {
Snackbar.make(parent_view, R.string.msg_cart_empty, Snackbar.LENGTH_SHORT).show();
}
} else if (item_id == R.id.action_delete) {
if (adapter.getItemCount() == 0) {
Snackbar.make(parent_view, R.string.msg_cart_empty, Snackbar.LENGTH_SHORT).show();
return true;
}
dialogDeleteConfirmation();
}
return super.onOptionsItemSelected(item);
}
我正在这样做但没有成功
@Override
protected void onCreate(final Bundle savedInstanceState) {
Clicked = (Button)findViewById(R.id.button);
Clicked.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onOptionsItemSelected();
}
});