public class ShuDuKuActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//为每个按钮设置点击监听
View continueButton = this.findViewById(R.id.button_continue);
continueButton.setOnClickListener((OnClickListener) this);
View newButton = this.findViewById(R.id.button_new_game);
newButton.setOnClickListener((OnClickListener) this);
View aboutButton = this.findViewById(R.id.button_about);
aboutButton.setOnClickListener((OnClickListener) this);
View exitButton = this.findViewById(R.id.button_exit);
exitButton.setOnClickListener((OnClickListener) this);
}里面的View continueButton = this.findViewById(R.id.button_continue); this指针指哪个对象?
continueButton.setOnClickListener((OnClickListener) this);这里的this指针又是指哪个对象?跟上面一样的吗?
新手求学习,谢谢各位
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//为每个按钮设置点击监听
View continueButton = this.findViewById(R.id.button_continue);
continueButton.setOnClickListener((OnClickListener) this);
View newButton = this.findViewById(R.id.button_new_game);
newButton.setOnClickListener((OnClickListener) this);
View aboutButton = this.findViewById(R.id.button_about);
aboutButton.setOnClickListener((OnClickListener) this);
View exitButton = this.findViewById(R.id.button_exit);
exitButton.setOnClickListener((OnClickListener) this);
}里面的View continueButton = this.findViewById(R.id.button_continue); this指针指哪个对象?
continueButton.setOnClickListener((OnClickListener) this);这里的this指针又是指哪个对象?跟上面一样的吗?
新手求学习,谢谢各位
怎么感觉这个this指针可以随便强制转换的?
{
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.new_game_title);
builder.setItems(R.array.difficulty,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
startGame(which);
}
})
.show();
}
private void startGame(int i){
Log.d(TAG, "clicked on" + i);
}为什么这里面的Builder builder = new AlertDialog.Builder(this); this指针又不用强制转换呢?
本人混乱了,明明这个 AlertDialog.Builder()的参数是Context context 为什么可以用THIS指针啊
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.view.ContextThemeWrapper
↳ android.app.Activity