我在我的android项目中使用此代码:
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
Run Code Online (Sandbox Code Playgroud)
但是,Eclipse说它已setButton()被弃用.请帮助我提供替代解决方案.谢谢!
我想提示用户使用对话框在我的android应用程序中输入.这是我发现的:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText();
// Do something with value!
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
Run Code Online (Sandbox Code Playgroud)
但这给了我:
android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用程序
我的代码有什么问题似乎在对话框上传递了一个null参数,但我无法找出问题所在.
我以编程方式添加按钮,按钮的数量取决于某些条件.要为RelativeLayout.LayoutParams添加规则,将Buttons对齐到彼此的顶部,我需要设置它们的ID.从2 - 3年前的所有答案都说setId(int)是可以的(例如setId(1)),但是现在它被禁止了(UPD.只有int literals它才行.用int变量一切都好.想知道为什么).现在怎么办?