0

Previously, I used an AppController class extends from Application and in Manifest, that is added. Now, I prepare a signupModel class. In this class, I need LayoutInflater because of context. But when debugging, context has AppController. However, I want context is not include 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();
}

}

4

1 回答 1

0

我会这样做,使用静态类 LayoutInflater消除对上下文和系统服务的需要

public SignUpModel(){
        View view = LayoutInflater.inflate(R.layout.activity_sign_up,null);
        signup_email = (EditText) view.findViewById(R.id.signup_email);
    }
于 2016-06-21T07:49:18.017 回答