Here is my issue: I am downloading Images from a server async and organize them in an array such as Image[1] would b the equivalent of Image1 the reason why I need the array to be organized is that I am trying to have an image rotating in 360 angle. So when I download the images into the array it seems that it's not doing the job correctly. Any advice is super greatly appreciated.
public class tst extends Activity implements OnClickListener {
TextView t;
Button b1;
ImageView iV;
Bitmap bitmap = null;
Bitmap [] angles;
String stringAngle;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
angles = new Bitmap[13];
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
iV = (ImageView) findViewById(R.id.imageView1);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.button1){
//Toast.makeText(getApplicationContext(), "ghjh", Toast.LENGTH_SHORT).show();
for(int i = 1 ; i<13 ; i++)
{
stringAngle = Integer.toString(i);
new DownloadImageTask()
.execute("http://www.sampleurl"
+stringAngle+".png");
}
iV.setImageBitmap(angles[7]);
}
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
protected Bitmap doInBackground(String... urls) {
return loadImageFromNetwork(urls[0]);
}
protected void onPostExecute(Bitmap result) {
// Do something with bitmap eg:
for(int m = 1 ; m<13;m++)
{
angles[m] =(Bit开发者_高级运维map) result;
}
}
}
private Bitmap loadImageFromNetwork(String url) {
try {
bitmap = BitmapFactory.decodeStream((InputStream) new URL(url)
.getContent());
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
}
in this case iV.setImageBitmap(angles[7]) always comes back with different results.
精彩评论