2013-12-12 111 views
0

我只想點擊圖片和一個對話框就會出現,在那個對話框中有幾個圖像我只是選擇了該圖像,我的圖像應該被該圖像替換,但我的圖像視圖變爲空白其不低於更換Imageview沒有刷新android

imgJuice.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      final Resources resources = getResources(); 
      final Dialog dialog = new Dialog(getActivity(), 
        android.R.style.Theme_Dialog); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.choose_juice_image_dialog); 

      ImageView imgJuiceOrange = (ImageView) dialog 
        .findViewById(R.id.imgJuiceOrange); 
      imgJuiceOrange.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 

        imgJuice.setImageDrawable(resources 
          .getDrawable(R.id.imgJuiceOrange)); 
    // also i have tried with setImageResource but nothing will be happen 

        dialog.dismiss(); 
       } 
      }); 
     } 

回答

3

使用圖像

我的代碼是下面的代碼:

@Override 
public void onClick(View v) { 
    imgJuice.setImageDrawable(resources 
     .getDrawable(R.drawable.imgJuiceOrange)); 
    dialog.dismiss(); 
} 

imgJuiceOrangedrawable不是id

+0

對不起,我忘了:( –

+0

偏偏..... :) – JiTHiN

-1

你也忘了添加dialog.show()這裏: -

imgJuice.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      final Resources resources = getResources(); 
      final Dialog dialog = new Dialog(getActivity(), 
        android.R.style.Theme_Dialog); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.choose_juice_image_dialog); 

      ImageView imgJuiceOrange = (ImageView) dialog 
        .findViewById(R.id.imgJuiceOrange); 
      imgJuiceOrange.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 

        imgJuice.setImageDrawable(resources 
          .getDrawable(R.id.imgJuiceOrange)); 
    // also i have tried with setImageResource but nothing will be happen 

        dialog.dismiss(); 
       } 
      }); 
      //Dialog Show code missing 
      dialog.show(); 
     } 
+0

@ komal-我貼出來了一個錯誤,我得到downvoted。好 –