如何检查是否选择了警报对话框项目?
How to check alert dialog item selected or not?
我在文本视图上设置了警报对话框,我在其中使用了字符串数组,现在如何检查是否选择了 none 项目,如果选择了 none 项目则不应提交..检查下面我的代码片段..提前致谢..
sp3=(TextView)findViewById(R.id.daydates);
btnsubmit=(Button)findViewById(R.id.btnreg);
final String[] items = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
final ArrayAdapter<String> adapter123 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, items);
sp3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(RegistrationForm.this)
.setTitle("Select Day")
.setAdapter(adapter123, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sp3.setText(adapter123.getItem(which).toString());
dialog.dismiss();
}
}).create().show();
}
});
btnsubmit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(emailtext.getText().toString().trim().length() > 0 && passtext.getText().toString().trim().length() > 0 && confirmpass.getText().toString().trim().length() > 0 && username.getText().toString().trim().length() > 0 && firstname.getText().toString().trim().length() > 0 && lastname.getText().toString().trim().length() > 0 && isSetDay==true && isSetMonth==true && isSetYear==true && isSetPro==true)
{
isSetDay=false;
isSetMonth=false;
isSetYear=false;
isSetPro=false;
new AttemptLogin().execute();
final String uname=username.getText().toString();
if(!isValidUserName(uname))
{
username.setError("Invalid User Name");
}
final String fname=firstname.getText().toString();
if(!isValidFirstName(fname))
{
firstname.setError("Invalid First Name");
}
final String lname=lastname.getText().toString();
if(!isValidLastName(lname))
{
lastname.setError("Invalid Last Name");
}
}
else
{
Toast.makeText(getApplicationContext(), "Fill the details", Toast.LENGTH_LONG).show();
}
break;
}
});
为什么不直接使用布尔值来确定在单击 btnsubmit 时是否已设置 sp3,然后在需要重新使用时重置它。
这是我的建议:
sp3=(TextView)findViewById(R.id.daydates);
btnsubmit=(Button)findViewById(R.id.btnreg);
boolean isSet = false;
final String[] items = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
final ArrayAdapter<String> adapter123 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, items);
sp3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(RegistrationForm.this)
.setTitle("Select Day")
.setAdapter(adapter123, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sp3.setText(adapter123.getItem(which).toString());
isSet = true;
dialog.dismiss();
}
}).create().show();
}
});
btnsubmit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(!isSet)
{
//Do Something
isSet = false;
}
}
});
我在文本视图上设置了警报对话框,我在其中使用了字符串数组,现在如何检查是否选择了 none 项目,如果选择了 none 项目则不应提交..检查下面我的代码片段..提前致谢..
sp3=(TextView)findViewById(R.id.daydates);
btnsubmit=(Button)findViewById(R.id.btnreg);
final String[] items = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
final ArrayAdapter<String> adapter123 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, items);
sp3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(RegistrationForm.this)
.setTitle("Select Day")
.setAdapter(adapter123, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sp3.setText(adapter123.getItem(which).toString());
dialog.dismiss();
}
}).create().show();
}
});
btnsubmit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(emailtext.getText().toString().trim().length() > 0 && passtext.getText().toString().trim().length() > 0 && confirmpass.getText().toString().trim().length() > 0 && username.getText().toString().trim().length() > 0 && firstname.getText().toString().trim().length() > 0 && lastname.getText().toString().trim().length() > 0 && isSetDay==true && isSetMonth==true && isSetYear==true && isSetPro==true)
{
isSetDay=false;
isSetMonth=false;
isSetYear=false;
isSetPro=false;
new AttemptLogin().execute();
final String uname=username.getText().toString();
if(!isValidUserName(uname))
{
username.setError("Invalid User Name");
}
final String fname=firstname.getText().toString();
if(!isValidFirstName(fname))
{
firstname.setError("Invalid First Name");
}
final String lname=lastname.getText().toString();
if(!isValidLastName(lname))
{
lastname.setError("Invalid Last Name");
}
}
else
{
Toast.makeText(getApplicationContext(), "Fill the details", Toast.LENGTH_LONG).show();
}
break;
}
});
为什么不直接使用布尔值来确定在单击 btnsubmit 时是否已设置 sp3,然后在需要重新使用时重置它。
这是我的建议:
sp3=(TextView)findViewById(R.id.daydates);
btnsubmit=(Button)findViewById(R.id.btnreg);
boolean isSet = false;
final String[] items = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
final ArrayAdapter<String> adapter123 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, items);
sp3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(RegistrationForm.this)
.setTitle("Select Day")
.setAdapter(adapter123, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sp3.setText(adapter123.getItem(which).toString());
isSet = true;
dialog.dismiss();
}
}).create().show();
}
});
btnsubmit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(!isSet)
{
//Do Something
isSet = false;
}
}
});