【发布时间】:2013-10-11 17:08:59
【问题描述】:
有人可以帮帮我吗? 当我单击按钮时,没有任何反应。我对android编程很陌生,所以请按我的理解回答。
(不要怀疑我的变量)
谢谢
@Override
public void onClick(View v) {
Button preis = (Button) findViewById(R.id.essenpreis);
preis.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Creating alert Dialog with one Button
AlertDialog.Builder alertDialog = new AlertDialog.Builder(options.this);
// Setting Dialog Title
alertDialog.setTitle("Essenspreis");
// Setting Dialog Message
alertDialog.setMessage("Neuen Preis eintragen:");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Setting OK Button
alertDialog
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// Write your code here to execute after dialog closed
Toast.makeText(getApplicationContext(),"Preis geändert!", Toast.LENGTH_SHORT).show();
}
});
// Showing Alert Message
alertDialog.show();
}
});
}
}
【问题讨论】:
-
你确定onclicked被调用了吗?
-
onClick 你设置这个按钮点击什么?