我有一个EditText输入对话框.当我单击对话框上的"是"按钮时,它将验证输入,然后关闭对话框.但是,如果输入错误,我想保持在同一个对话框中.每次无论输入是什么,当我点击"否"按钮时,对话框应自动关闭.我怎么能禁用它?顺便说一句,我已经使用PositiveButton和NegativeButton作为对话框上的按钮.
android dialog android-alertdialog android-dialog android-dialogfragment
我想在加空字段验证EditText上AlertDialog。但是即使字段为空,也不会显示错误消息,而是AlertDialog is closing. But if conditions are working well as I'm not able to do post operations if any of the field is empty.
这是我的Java示例代码:
public class TourActivity extends AppCompatActivity {
private LayoutInflater inflater;
private FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tour);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
inflater = TourActivity.this.getLayoutInflater();
View content = inflater.inflate(R.layout.activity_add_new_trip, null);
final EditText editEvent …Run Code Online (Sandbox Code Playgroud) 我正在测试AlertDialog的行为以集成到更大的组件中.我无法再显示相同的对话框.这是测试代码:
public class MainActivity extends AppCompatActivity {
private AlertDialog alertDialogACCreationRetry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alertDialogACCreationRetry = new AlertDialog.Builder(this)
.setTitle("Account creation failed")
.setMessage("There was a problem connecting to the Network. Check your connection.")
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
alertDialogACCreationRetry.show();
alertDialogACCreationRetry.show();
}
}
Run Code Online (Sandbox Code Playgroud)
我试过把alertDialogACCreationRetry.show();里面的重试按钮但仍然不会显示.我也试过放入alertDialogACCreationRetry.dismiss();重试按钮,然后alertDialogACCreationRetry.show();在外面打电话,它仍然没有显示.更令人恐惧的是,如果不允许这样做,它就不会给我一个例外.
所以,我的问题是:每次按下按钮后(自动)解除后,我是否必须每次创建一个新的Dialog?