在Android中单击ImageView时显示FC错误
单击在Android中单击ImageView时显示FC错误,android,android-fragments,android-view,Android,Android Fragments,Android View,单击imageview后,我想在imageview中显示图像。我使用片段来显示内容,我需要在对话框中显示大图像。但是当点击ImageViewshow me FC error时 我的片段代码: public class root_mobile_fragment extends Fragment { Bundle savedInstanceState; private CardView mobile_dl; private ImageView mobile_iamge1;
imageview
后,我想在imageview
中显示图像。我使用片段来显示内容,我需要在对话框中显示大图像。但是当点击ImageView
show me FC error时
我的片段代码:
public class root_mobile_fragment extends Fragment {
Bundle savedInstanceState;
private CardView mobile_dl;
private ImageView mobile_iamge1;
Context context;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.root_mobile_xml, container, false);
mobile_dl = (CardView) view.findViewById(R.id.mobile_adApp);
mobile_dl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://soft-mgyun-com.qcloudcdn.com/files/products/romastersu/2075/2016/70/RomasterSu_3.0.0_160104_2075.apk"));
startActivity(browserIntent);
}
});
mobile_iamge1 = (ImageView) view.findViewById(R.id.mobile_root_image1);
mobile_iamge1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(getActivity());
LayoutInflater inflater2 = LayoutInflater.from(getActivity());
View newView = (View) inflater2.inflate(R.layout.image_dialog, null);
ImageView image_2 = (ImageView) newView.findViewById(R.id.mobile_root_image1);
image_2.setImageResource(R.drawable.iroot_1);
dialog.show();
}
});
return view;
}
}
图像布局XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mobile_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:background="@color/white"
android:foreground="?android:attr/selectableItemBackground">
<ImageView
android:id="@+id/image_dialog_big"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</android.support.v7.widget.CardView>
</RelativeLayout>
我怎样才能修好它?tnx all我认为您在对话框中使用了错误的id
作为ImageView
你有
<ImageView
android:id="@+id/image_dialog_big"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
在xml中,但您正在java代码中使用R.id.mobile\u root\u image1
访问ImageView
,这会导致NullPointerException
,正如您在logcat输出中看到的那样。
改变
ImageView image\u 2=(ImageView)newView.findViewById(R.id.mobile\u root\u image1)代码>
到
ImageView image\u 2=(ImageView)newView.findviewbyd(R.id.image\u对话框\u大)代码>在活动中替换此行
mobile_iamge1 = (ImageView) view.findViewById(R.id.mobile_root_image1);
与
使用此选项显示对话框
在你的舌头里试试这个
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_dialog);
ImageView image_2 =(ImageView) dialog.findViewById(R.id.mobile_root_image1);
image_2.setImageResource(R.drawable.iroot_1);
});
dialog.show();
并确保image_dialog xml文件包含mobile_root_image1作为图像视图的ID,如何修复它?你能给我发个真实的代码来修复它吗?(fekr konam shomam farsi zaban Hastin,Mammon misham komak koni chon vaqean niaz daram)我亲爱的朋友。没关系。(aslan havasam nabood,bade inke goftin raftam didam che eshtebahe Sadei karde boodam.mitoonam ba shoma dar ertebat basham?)欢迎您:)(哈特曼,地址e电子邮件e man To个人资料我有)
mobile_iamge1 = (ImageView) view.findViewById(R.id.image_dialog_big);
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_dialog);
ImageView image_2 =(ImageView) dialog.findViewById(R.id.mobile_root_image1);
image_2.setImageResource(R.drawable.iroot_1);
});
dialog.show();