比如我在a类要引用了自定义对话框并往里面输入了数据,现在我要对自定义对话框进行监听,代码没报错,但是一打开要弹出对话框的时候就崩了。是我写错地方了吗,应该怎么写private void init(final View view) { TextView tv_class = (TextView) view.findViewById(R.id.tv_class); tv_class.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { LayoutInflater inflater = getLayoutInflater(null); View layout = inflater.inflate(R.layout.dialog, (ViewGroup) view.findViewById(R.id.dialog)); AlertDialog.Builder builder = new AlertDialog.Builder(Fragment1.super.getContext()) .setView(layout); builder.create().show(); final EditText classname = (EditText) view.findViewById(R.id.class_name); final EditText classroom = (EditText) view.findViewById(R.id.class_room); final EditText classtime = (EditText) view.findViewById(R.id.class_time); final EditText classteacher = (EditText) view.findViewById(R.id.class_teacher); Button classd = (Button) view.findViewById(R.id.class_d); classd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SharedPreferences preferences=getActivity().getSharedPreferences("class1", Context.MODE_PRIVATE); SharedPreferences.Editor editor=preferences.edit(); String name = classname.getText().toString(); String room = classroom.getText().toString(); String time = classtime.getText().toString(); String teacher = classteacher.getText().toString(); editor.putString("classname",name); editor.putString("classroom",room); editor.putString("classtime",time); editor.putString("classteacher",teacher); editor.commit(); } }); } }); /* SharedPreferences preferences=getActivity().getSharedPreferences("class1", Context.MODE_PRIVATE); String name =preferences.getString("classname", ""); String room =preferences.getString("classroom", ""); String time =preferences.getString("classtime", ""); String teacher =preferences.getString("classteacher", "");*/}
- 2 回答
- 0 关注
- 1008 浏览
添加回答
举报
0/150
提交
取消