请问哪里错了?
package com.ab.demo2;
import android.os.Bundle;
import android.util.Log;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
@SuppressLint("ShowToast")
public class MainActivity extends Activity {
private Button bt1;
private Button bt2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button) findViewById(R.id.button1);
bt2 = (Button) findViewById(R.id.button2);
/*bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO 自动生成的方法存根
}
});*/
bt1.setOnClickListener(new MyOnClickListener(){
@Override
public void onClick(View v) {
// 调用父类的OnClick事件
super.onClick(v);
Toast.makeText(MainActivity.this, "bt1要执行的逻辑", 1).show();
}
});
bt2.setOnClickListener(new MyOnClickListener(){
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
super.onClick(v);
Toast.makeText(MainActivity.this, "bt2要执行的逻辑", 1).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class MyOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
v.setAlpha(0.5f);
}
}
}