[英]Android - Trying to make Dialog with ImageView code
What I'm trying to do is when an Imageview item being preesed, then a Dialog will open up and show the inage in a large scale. 我想要做的是当一个Imageview项目被预先播放时,然后会打开一个Dialog并大规模显示该内容。
Now first of all this is the XML layout of the dialog - 现在首先是对话框的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/imageView_large_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bkgnd_pressed" />
</LinearLayout>
Now the code to the Dialog is as follows - 现在Dialog的代码如下 -
Dialog settingsDialog = new Dialog(MainChat.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_large
, null));
ImageView ivLarge = (ImageView) findViewById(R.id.imageView_large_pic);
String pathpic = v.getTag().toString();
ivLarge.setImageURI(Uri.parse(pathpic));
settingsDialog.show();
Now I tried to dubuging this code, and it get stuck at this line - ivLarge.setImageURI(Uri.parse(pathpic));
现在我试图对这段代码进行调整,并且它会卡在这一行 -
ivLarge.setImageURI(Uri.parse(pathpic));
The logcat gives me that this is java.lang.NullPointerException error. logcat告诉我这是java.lang.NullPointerException错误。
Thanks for any kind of help 谢谢你的帮助
You are looking in the wrong place for the ImageView
您正在寻找
ImageView
的错误位置
ImageView ivLarge = (ImageView) findViewById(R.id.imageView_large_pic);
is looking in the layout
you inflate in setContentView()
. 正在查看你在
setContentView()
膨胀的layout
。 Instead, you need to look in the Dialog
's layout. 相反,您需要查看
Dialog
的布局。 Try instead 试试吧
ImageView ivLarge = (ImageView) settingsDialog .findViewById(R.id.imageView_large_pic);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.