Note that there are some explanatory texts on larger screens.

plurals
  1. POChange text and icon in a Custom Toast?
    primarykey
    data
    text
    <p>I'm having some issues when I trying to show a custom toast (with icon and message). This is the code.</p> <pre><code>private void makeToast(String text, int icon) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.message)); ((TextView) layout.findViewById(R.id.message)).setText(text); layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.icon)); // 0 - Exclamation, 1 - Noow icon if(icon == 0){ ((ImageView) layout.findViewById(R.id.icon)).setImageResource(R.drawable.exclamation); }else if(icon == 1){ ((ImageView) layout.findViewById(R.id.icon)).setImageResource(R.drawable.nicon); } Toast toast = new Toast(getBaseContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); } </code></pre> <p>I want to change the icon and message when the second parameter is 0 or 1. I know the problem is in the call to the second layout, but I don't know how to solve it.</p> <p>Thanks you.</p> <p>Edit:</p> <p>I call this method from a onPostExecute in a AsyncTask. I forgot to tell this.</p> <pre><code>Thread [&lt;11&gt; AsyncTask #1] (Suspended (exception RuntimeException)) ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: not available ThreadPoolExecutor$Worker.run() line: not available Thread.run() line: not available </code></pre> <p>Edit 2:</p> <pre><code>@Override protected void onProgressUpdate(Void... values) { super.onProgressUpdate(values); makeToast("loading nightclubs...", 1); } } </code></pre> <p>Edit 3:</p> <pre><code>@Override protected void onPostExecute(List&lt;Category&gt; result) { Log.i("result", result.toString()); // Cargamos el listado a pasarle a categoryId en la // consulta for (int k = 0; k &lt; result.size(); k++) { ALLOFTHEM += result.get(k).getId(); if (k &lt; result.size() - 1) { ALLOFTHEM += ","; } } Log.i("POST", ALLOFTHEM); } </code></pre> <p><strong>SOLVED!!!</strong></p> <p>I have used...</p> <pre><code>runOnUiThread(new Runnable() { public void run() { makeToast("loading nightclubs...", 1); } }); </code></pre> <p>...everytime I want a toast in a UI and it works good.</p> <p>Thanks to all of you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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