Reputation: 3
Within my UI thread I have the following code which works perfectly
public void showButtons(boolean visible) {
if (visible) {
mTextView.setText(currentSwipe.cardID);
btnSignIn.setVisibility(Button.VISIBLE);
btnSignOut.setVisibility(Button.VISIBLE);
}
else {
mTextView.setText(R.string.Please_swipe);
btnSignIn.setVisibility(Button.INVISIBLE);
btnSignOut.setVisibility(Button.INVISIBLE);
}
}
I also have this Async class
private class AwaitResponse extends AsyncTask<clockItem, Void, Boolean>{
protected Boolean doInBackground(clockItem... params){
clockItem rSwipe = (clockItem)params[0];
Calendar cSwipe = rSwipe.swipeDate;
SystemClock.sleep(5000);
if (currentSwipe.swipeDate == cSwipe)
{
currentSwipeSave();
return true;
}
return false;
}
protected void onPostExecute(Boolean SwipeActive){
if (SwipeActive) {
btnSignIn.setVisibility(Button.INVISIBLE);
btnSignOut.setVisibility(Button.INVISIBLE);
mTextView.setText(R.string.Please_swipe);
}
}
}
Within the onPostExecute I have tried calling the showButtons(false) which has the same result as this code that is to change the text on mTextView but leave the Buttons visible. They seem to be disabled but remain visible. If I remark out the setText line, the Buttons react correctly i.e. disappear.
Am I missing something obvious here?
The idea is once an nfc swipe is read, the user is presented with 2 buttons. If neither button is pressed after 5 seconds, an indeterminate direction is filed against the swipe. If a button is pressed, the appropriate direction is filed and the screen resets (hide buttons and show default text) ready for the next swipe. If a swipe is recorded, no buttons are pressed and a new swipe is made within 5 seconds, the previous swipe is files with an indeterminate direction and the new swipe options are displayed.
All of this seems to be working apart from the reset of the screen after the 5 second timeout. Any ideas why this may be?
Upvotes: 0
Views: 36
Reputation: 4917
Try this...
public void showButtons(boolean visible) {
if (visible) {
mTextView.setText(currentSwipe.cardID);
btnSignIn.setVisibility(View.VISIBLE);
btnSignOut.setVisibility(View.VISIBLE);
}
else {
mTextView.setText(R.string.Please_swipe);
btnSignIn.setVisibility(View.INVISIBLE);
btnSignOut.setVisibility(View.INVISIBLE);
}
}
private class AwaitResponse extends AsyncTask<clockItem, Void, Boolean>{
protected Boolean doInBackground(clockItem... params){
clockItem rSwipe = (clockItem)params[0];
Calendar cSwipe = rSwipe.swipeDate;
SystemClock.sleep(5000);
if (currentSwipe.swipeDate == cSwipe)
{
currentSwipeSave();
return true;
}
return false;
}
protected void onPostExecute(Boolean SwipeActive){
if (SwipeActive) {
showButtons(!SwipeActive);
}
}
}
Upvotes: 0
Reputation: 5261
change
btnSignIn.setVisibility(Button.INVISIBLE);
to
btnSignIn.setVisibility(View.INVISIBLE);
Upvotes: 1