比如我在a類要引用了自定義對(duì)話框并往里面輸入了數(shù)據(jù),現(xiàn)在我要對(duì)自定義對(duì)話框進(jìn)行監(jiān)聽,代碼沒(méi)報(bào)錯(cuò),但是一打開要彈出對(duì)話框的時(shí)候就崩了。是我寫錯(cuò)地方了嗎,應(yīng)該怎么寫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 關(guān)注
- 1045 瀏覽
添加回答
舉報(bào)
0/150
提交
取消