在我的活動我有一個ImageView的ImageView的不正確加載
XML代碼:
<!-- 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>
這是活動時間:
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(position); position++; } }); } // 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(); }
我第一次調用這個方法,(位置= 0)圖像不加載。之後,圖像加載正確。
第一次加載圖像我該怎麼做?
(我無法使用android:src="@drawable/x"
加載XML中的圖像),因爲圖像可能隨時不同。 EDITED!