lundi 2 mars 2015

ImageView is not loading correctly

In my Activity I have one ImageView


XML Code:



<!-- FOTO LATERAL! -->

<ImageView
android:id="@+id/simbolo_raca"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

/>
<Button
android:id="@+id/button_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok. Seguinte Pergunta"
android:layout_gravity="right"
android:gravity="right"
android:paddingRight="30dip"
</LinearLayout>


This is the Activity:




public class QuestionarioActivityRaca extends Activity{
ImageView simbolo;
Int position;
Button B_Save;
List<Drawable> List_imagens = new ArrayList<Drawable>();
@Override
public void onCreate(Bundle savedInstanceState) {
simbolo = (ImageView) findViewById(R.id.simbolo_raca);
B_Save = (Button) findViewById(R.id.button_save);
position = 0;
List_imagens.add(getResources().getDrawable(R.drawable.p1));
List_imagens.add(getResources().getDrawable(R.drawable.p2));
List_imagens.add(getResources().getDrawable(R.drawable.p3));
List_imagens.add(getResources().getDrawable(R.drawable.p4));
loadNewImage(position);
B_Save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
loadNewImage();
}
});
}
// I Use this method to load the Image
public loadNewImage(int Page)
{
new Thread(new Runnable(){
@Override
public void run(){
simbolo.post(new Runnable(){
@Override
public void run()
{
simbolo.setImageDrawable(List_imagens.get(Page));
}
});
}
}).start();
}


The first time I call this method, (position = 0) the image doesnt loads. After that, the image is loading correctly.


How I have to do to load the image the first time?


(I can not load the image in the XML using android:src="@drawable/x") because the image could be different anytime.


Aucun commentaire:

Enregistrer un commentaire