Note that there are some explanatory texts on larger screens.

plurals
  1. POonClick Listener Code doesn't show Toasts
    text
    copied!<p>I have a simple layout employing 3 buttons. I have a listener on the first button. It gets called as expected on a click. The listener checks a few things, possible downloads a few files, then starts another activity.</p> <p>During the file download, I'd like to inform the user that a download is going on. I tried the usual suspects, but I saw that using a ProgressBar would be alot of code. So I tried something smaller: I used a Toast to display a message, then disable the 3 buttons for the download duration. This is the code:</p> <pre><code>int version_pre = getCurrentVersion(); //Check files on remote server String URL = Data._URL + "/" + Data.OWNER + "/version"; if(!this.downloadFile(URL, "version")) { Toast.makeText(this, "Download der Dateien fehlgeschlagen. Fahre mit lokaler Version fort.", Toast.LENGTH_LONG).show(); } int version_post = getCurrentVersion(); if(version_pre != version_post) { //Neu Dateien besorgen Button b1 = (Button)findViewById(R.id.btn_Prospekt); b1.setEnabled(false); b1 = (Button)findViewById(R.id.btn_Einheitenumrechner); b1.setEnabled(false); b1 = (Button)findViewById(R.id.btn_Sonstiges); b1.setEnabled(false); Toast.makeText(this, "Aktualisierung der Dateien wird gestartet.", Toast.LENGTH_LONG).show(); if(!fetchAllFiles()) { Toast.makeText(this, "Download der Dateien fehlgeschlagen. Fahre mit lokaler Version fort.", Toast.LENGTH_LONG).show(); } b1 = (Button)findViewById(R.id.btn_Prospekt); b1.setEnabled(true); b1 = (Button)findViewById(R.id.btn_Einheitenumrechner); b1.setEnabled(true); b1 = (Button)findViewById(R.id.btn_Sonstiges); b1.setEnabled(true); } return ""; </code></pre> <p>The problem is this: Even when debugging, I cannot see that any of the GUI changing mechanisms actually do anything. Disabling the buttons should grey them out. It doesn't. Calling the Toast.maketext().show() should display a message. It doesn't.</p> <p>I suspect that this might be expected behaviour as it concerns multiple mechanisms. Is there a restriction as to what I can call in an action listener that will change the UI? Do I need to call a refresh() kinda method when changing the UI while in a Listener?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload