¿Cómo puedo hacer múltiples enlaces URL muestran en la matriz?
Pregunta
Im nuevo en la programación androide y me dieron un sencillo recuperar imagen de la URL de trabajo, pero confundido sobre cómo hacerlo, así que puede cargar varias imágenes de mi páginas web url. Alguien informó a cambiar el dibujable de cadena, pero no estoy seguro al 100% cómo hacerlo aquí está la mayor parte de mi código hasta ahora:
public class Gallery extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imgView =(ImageView)findViewById(R.id.ImageView01);
Drawable drawable = LoadImageFromWebOperations("http://www.mandarichmodels.com/hot-pics/4.jpg", "http://www.mandarichmodels.com/hot-pics/5.jpg");
imgView.setImageDrawable(drawable);
}
private Drawable LoadImageFromWebOperations(String url, String string) {
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
}
Solución
Crea una matriz o lista de las URL que desea tirar de, y luego usar el mismo código que tiene, pero ponerlo en un bucle sobre la longitud de la matriz o lista. Y usted debe hacer esto en un hilo separado para que no se genera una ANR. Busque AsyncTask.
List<String> urls;
for(int i=0; i<urls.size(); i++) {
Drawable d = LoadImageFromWebOperations(urls.get(i));
// do something interesting
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow