接口方式监听按钮点击事件,是对的吗?谢谢。。。
package com.example.outonclick7_30;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.os.Build;
public class MainActivity extends ActionBarActivity implements OnClickListener {
private static final OnClickListener Listener = null;
private Button loginbutton;
private ImageButton imgBt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginbutton=(Button) findViewById(R.id.button1);
imgBt=(ImageButton) findViewById(R.id.imageButton1);
loginbutton.setOnClickListener(Listener);
imgBt.setOnClickListener(this);
}
OnClickListener listener=new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("tag", "被触发了");
}
};
/* {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
System.out.print("可以了");
}
});
*/
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("tag", "第三种打印方式");
}
}