检查后要求用户打开互联网服务,然后我尝试点击按钮,我的应用程序崩溃并显示错误消息
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Run Code Online (Sandbox Code Playgroud)
在这条线上它崩溃了,我试过这样做但是没有完全解决
if(alert.getContext() != null){
alert.show();
}
Run Code Online (Sandbox Code Playgroud)
这是完整的代码
else if (id == R.id.xyz) {
//startActivity(borrowIntent);
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert.setTitle("xyz");
input.setFilters(new InputFilter[] {
// Maximum 2 characters.
new InputFilter.LengthFilter(6),
// Digits only.
DigitsKeyListener.getInstance(),
});
// Digits only & use numeric soft-keyboard.
input.setKeyListener(DigitsKeyListener.getInstance());
input.setHint("xyz");
alert.setView(input);
alert.setPositiveButton("Borrow", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(input.getText().length() == 0)
{
input.setError("xyz is required …Run Code Online (Sandbox Code Playgroud) 我不喜欢管理XML和Java在一起,用我可以创造同样的GUI Java的语言?我怎么能这样做,你能告诉我简单的代码Button吗?我会很感激你的答案.