注意,此时,inflater填充布局之后返回的是一个view对象,如果此时直接用getActivity查找下一个控件,会空指针异常. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_my_singin, null);//布局初始化 dl= (TextView) view.findViewById(R.id.tv_dl); dl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToastUtils.makeLongText("登录按钮被点击了",getActivity()); } }); /*dl= (TextView) getActivity().findViewById(R.id.tv_dl);//初始化登录按钮*/ /*dl.setOnClickListener(new View.OnClickListener() { @Override //此处的登录按钮需要一个判断,即是否已经登录,或者已经注册,则直接保存住密码 //此处暂为直接跳转 public void onClick(View v) { Intent intent=new Intent(getActivity(),SinginActivity.class); startActivity(intent); *//*getActivity().finish();*//* } });*/ /*passwordEt = (EditText) view.findViewById(R.id.id_login_name_et);//账号框 loginEt = (TextView) view.findViewById(R.id.id_password_et);//密码输入框 tv_forget_password = view.findViewById(R.id.tv_forget_password);//忘记密码 registerBtn = view.findViewById(R.id.register_account);//注册账号 textView = view.findViewById(R.id.textView);//登录 textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*//*Intent intent=new Intent(getActivity(),SinginActivity.class); startActivity(intent); } });
时间: 2024-11-10 10:12:55