我的应用在我的Dialog
activity
中显示onCreate
。所以我创建了一个CustomDialog
,它运行正常。
我想在EditText
中获得Parent Activity
CustomDialog
的值,但它给了我一个NULLPointerExecption
这是我的代码:
对话框:
public class VerifyDialog extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes;
public VerifyDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.verify_dialog);
yes = (Button) findViewById(R.id.btn_yes);
yes.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Check();
//Sending new Activity to verify pin of user
Intent i = new Intent(c, ProcessPinCode.class);
EditText phone_number = (EditText) findViewById(R.id.phone_number);
String phone = phone_number.getText().toString();
i.putExtra("response", phone);
c.startActivity(i);
}
private void Check() {
// TODO Auto-generated method stub
String OrgPin;
VerifyActivity v = new VerifyActivity();
String new_txt = v.t1.getText().toString();
System.out.print(new_txt);//**here i want to show**
OrgPin = v.getPinCode();
EditText org = (EditText) findViewById(R.id.pin_code_user);
if(!OrgPin.equals(org))
{
Toast.makeText(getContext(), "Pin Code not match", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
c.finish();
break;
default:
break;
}
dismiss();
}
}
调用名为“VerifyActivity”的对话框表单活动:
VerifyDialog cdd=new VerifyDialog(VerifyActivity.this);
cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
cdd.show();
有没有办法在Dialog中获取VerifyActivity Parent的EditText值?
谢谢你看看
答案 0 :(得分:0)
由于您已经有指向父Activity
的指针,因此只需将代码更改为此代码即可:
EditText phone_number = (EditText) c.findViewById(R.id.phone_number);
目前,您正在尝试使用标识R.id.phone_number
在对话框的布局中查找视图,但由于该EditText实际上位于活动的布局中,因此无法在对话框中找到。