In my app when user writes wrong character,my edittext becomes red then it becomes write.Actually ı am trying to make a red blink.This is my working code
class BlinkTask extends AsyncTask<EditText, Boolean, Boolean>
{
@Override
protected Boolean doInBackground(EditText... params) {
EditText et1=params[0];
try {
et1.setBackgroundColor(Color.RED);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
et1.setBackgroundColor(Color.WHITE);
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
}
but when I take et1.setBackgroundColor(Color.WHITE); out of try-catch block.It gives no error but unfortunately myapp has stopped.I checked loggat but saw nothing.this is false code class BlinkTask extends AsyncTask {
@Override
protected Boolean doInBackground(EditText... params) {
EditText et1=params[0];
try {
et1.setBackgroundColor(Color.RED);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
et1.setBackgroundColor(Color.WHITE);
return true;
}
}
I don't know why it needs try-catch although it gives no error.
also ı want to ask creating a asynctask class for this task is a good solution or nwhat else can be done.thank you
Aucun commentaire:
Enregistrer un commentaire