以前,我使用了一个AppController
类扩展自Application和Manifest,它被添加了。现在,我准备一个signupModel
课程。在本课程中,由于上下文,我需要LayoutInflater
。但是在调试时,上下文有AppController
。但是,我想上下文不包括AppController
?
public class SignUpModel {
Context context ;
EditText signup_email;
public SignUpModel(Context context){
this.context = context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.activity_sign_up,null);
signup_email = (EditText) view.findViewById(R.id.signup_email);
}
public String getEmail() {
return signup_email.getText().toString();
}
}
答案 0 :(得分:0)
我会这样做,使用静态类LayoutInflater ,无需上下文和系统服务
public SignUpModel(){
View view = LayoutInflater.inflate(R.layout.activity_sign_up,null);
signup_email = (EditText) view.findViewById(R.id.signup_email);
}