2015-12-23 54 views
0

在我的应用程序中,我有一个按钮,当取消时应该显示一个对话框,其中只包含一个图像,没有别的。该图像是从URL中检索的。但是,当点击按钮时,不会显示任何内容。在对话框中显示图像什么也没有

我的代码

public void onClick(View v){ 

    final Dialog dialog = new Dialog(SingleItemView.this); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    ImageView imgvw = new ImageView(SingleItemView.this); 
    String imgurl =descImgOne; 
    Uri imguri = Uri.parse(imgurl); 
    imgvw.setImageURI(imguri); 
    dialog.getWindow().getAttributes().windowAnimations = R.style.SmileWindow; 
    dialog.addContentView(imgvw, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
       ViewGroup.LayoutParams.MATCH_PARENT)); 

    dialog.show(); 
} 

凡descImgOne被分配一个URL链接

+0

你必须在此对话框中图片网址是什么? –

+0

@ Er.RakeshPrajapat我把它作为一个全局变量descImgOne – user5524159

+0

imgurl从http或local分配的URL吗? – phongvan

回答

0

使用需求使用setContentViewDialog custom layout

dialog.setContentView(R.layout.dialog_layout); 
+0

是的,我可以做到这一点,而不是定义一个新的布局文件只是想在dailog中的图像。感谢您的帮助 – user5524159

+0

哦!尝试这个。 http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html 或结帐这个http://stackoverflow.com/questions/4351204/android-progressdialog-with-setcontentview 。 –

0
imgvw.setBackgroundResource(R.drawable.app_launcher); 

试试这个,如果它呈现然后有一些问题在uri

+0

是的,你会尝试 – user5524159

+0

你可以发布** descImgOne ** – nakul

1
public void onClick(View v){ 

    final Dialog dialog = new Dialog(SingleItemView.this); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.customdialog); 

    ImageView imageView= (ImageView).dialog.findViewById(R.id.dialogimageview); 
    URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464"); 
    Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
    imageView.setImageBitmap(bmp); 

    dialog.show(); 
} 

customdialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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


</LinearLayout> 
+0

的值我知道这种方法,但想要做到这一点,而不需要定义一个新的xml – user5524159

+0

你想出来的布局 –

+0

是的。我想要它没有布局。不知道我的代码有什么问题 – user5524159

0

之一工作的代码(使用对话框内的Web视图)

AlertDialog.Builder alert = new AlertDialog.Builder(this); 

WebView wv = new WebView(this); 
wv.loadUrl("http://www.jjyproductions.com/wp-content/uploads/2014/02/IMG_3454-001.jpg"); 
wv.setWebViewClient(new WebViewClient() { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 

    view.loadUrl(url); 
    return true; 

    }  
}); 

    wv.setLayoutParams(new RelativeLayout.LayoutParams(
       ViewGroup.LayoutParams.MATCH_PARENT, 
       ViewGroup.LayoutParams.MATCH_PARENT)); 

    alert.setView(wv); 

    alert.setNegativeButton("Close", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.dismiss(); 
      } 
    }); 
    alert.show();