Note that there are some explanatory texts on larger screens.

plurals
  1. POGet ImageView drawable ID and change it with AsyncTask
    primarykey
    data
    text
    <p>What I want to do: get the id of the src of an ImageView, compare it to the ids of two drawables, and swap them, using AsyncTask (just because I want to understand how it works). I've read similar questions here, and so far this is what I've got:</p> <pre><code>public class Main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView image = (ImageView) findViewById(R.id.img); Integer integer = (Integer) image.getTag(); } private class cambiarImagen extends AsyncTask&lt;Integer, Integer, Integer&gt; { protected void onPreExecute() { ImageView image = (ImageView) findViewById(R.id.img); Integer integer = (Integer) image.getTag(); int img1 = R.drawable.zapato; int img2 = R.drawable.zapatod; } @Override protected Integer doInBackground(Integer... values) { // parte logica int num = values[0]; int zapato = values[1]; int zapatod = values[2]; if (num == zapato) { num = zapatod; } else if (num == zapatod) { num = zapato; } return num; } protected Void onPostExecute(Integer... values) { int num = values[0]; ImageView image = (ImageView) findViewById(R.id.img); image.setTag(num); return null; } } </code></pre> <p>Of course this doesn't work. 1. I don't understand how to get the id of the drawable that ImageView has as its src. 2. I don't understand how the params are passed in AsyncTask; onPreExecute should receive the UI stuff, doInbackground should receive it to compare it and return the drawable int that should be set to the ImageView, and onPreExecute should set it to the ImageView.</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.
 

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