0

How to make the text fade for only 20 seconds and then disappear when you click the button

This is the code

 public void scoreOpenB(View v) {

        findViewById(R.id.main_mess).setVisibility(View.GONE);

     ((TextView)findViewById(R.id.main_mess)).setText(R.string.btn_closs);
        findViewById(R.id.main_mess).setVisibility(View.VISIBLE );
    }
}
salem715
  • 19
  • 7

1 Answers1

0

You can use AsyncTask to update UI after delay. Try this ;)

    public void scoreOpenB(View v) {

        View updateMe = findViewById(R.id.main_mess);
        updateMe.setVisibility(View.GONE);

        new UpdateUI().execute(updateMe);
    }
}


private class updateUI extends AsyncTask<View, Integer, Long> {
    View toUpdate;

    protected void doInBackground(View view) {
        toUpdate = view;
        try {
            Thread.sleep(20000);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }

    protected void onProgressUpdate(Integer... progress) {
    }

    protected void onPostExecute(Long result) {
        (toUpdate(TextView)).setText(R.string.btn_closs);
        toUpdate.setVisibility(View.VISIBLE);

    }
}
Irwin Nawrocki
  • 337
  • 4
  • 7