android 第二次调用出错 网上说找到父view然后remove,但是不知道哪个是父view
在OnCearte():LayoutInflaterinflate=(LayoutInflater)getSystemService(Context.LAYOUT_INF...
在OnCearte():
LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vipForm = (LinearLayout)inflate.inflate(R.layout.vip, null);
vipEditText = (EditText)vipForm.findViewById(R.id.vipMsg);
自定义窗口的定义:
protected void vipApplyDialog() {
vipdialog = new AlertDialog.Builder(this);
vipdialog.setView(vipForm)
.setMessage("申请理由:")
.setPositiveButton("确定",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
VIPApplication vipApplication = new VIPApplicationImp(PersonalInformationActivity.this);
//第一个参数是商铺ID,第三个是申请信息
String returnString = vipApplication.applyVIP(context.getResources().getString(R.string.shopid)
, String.valueOf(preferences.getInt("memberid", 0))
, vipEditText.getText().toString());
if(returnString.equals("true")){
Toast.makeText(PersonalInformationActivity.this, "申请已提交!", 0).show();
}else{
Toast.makeText(PersonalInformationActivity.this, "申请提交失败!", 0).show();
}
}
})
.setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
}
})
.show();
}
自定义窗口的调用:
buttonVip = (Button) findViewById(R.id.buttonvip);
buttonVip.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
vipApplyDialog();
}
});
错误信息:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 展开
LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vipForm = (LinearLayout)inflate.inflate(R.layout.vip, null);
vipEditText = (EditText)vipForm.findViewById(R.id.vipMsg);
自定义窗口的定义:
protected void vipApplyDialog() {
vipdialog = new AlertDialog.Builder(this);
vipdialog.setView(vipForm)
.setMessage("申请理由:")
.setPositiveButton("确定",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
VIPApplication vipApplication = new VIPApplicationImp(PersonalInformationActivity.this);
//第一个参数是商铺ID,第三个是申请信息
String returnString = vipApplication.applyVIP(context.getResources().getString(R.string.shopid)
, String.valueOf(preferences.getInt("memberid", 0))
, vipEditText.getText().toString());
if(returnString.equals("true")){
Toast.makeText(PersonalInformationActivity.this, "申请已提交!", 0).show();
}else{
Toast.makeText(PersonalInformationActivity.this, "申请提交失败!", 0).show();
}
}
})
.setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
}
})
.show();
}
自定义窗口的调用:
buttonVip = (Button) findViewById(R.id.buttonvip);
buttonVip.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
vipApplyDialog();
}
});
错误信息:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 展开
展开全部
再你确定和取消按钮的事件结束前加 dialoginterface.dismiss()试试
如 取消那里
.setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
dialoginterface.dismiss();
}
})
如 取消那里
.setNegativeButton("取消",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
dialoginterface.dismiss();
}
})
追问
前辈~~不行咧~~还是同样的错误~~~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询