पर removeView() को कॉल करना होगा, मेरे पास मूल्य प्राप्त करने के लिए संवाद और कोडिंग बनाने के लिए एक कक्षा है। यह एक के लिए ठीक काम करता है। और जब मैं दूसरी बार संवाद कॉल करने का प्रयास करता हूं तो यह त्रुटि संदेश के बाद गुजरता है।निर्दिष्ट बच्चे के पास पहले से ही एक अभिभावक है। आपको बच्चे के माता-पिता को पहले
: java.lang.IllegalStateException: निर्दिष्ट बच्चे के पास पहले से ही एक अभिभावक है। आपको पहले बच्चे के माता-पिता पर removeView() को कॉल करना होगा।
क्या आप कृपया मुझे बता सकते हैं कि removeView() को कैसे हटाया जाए?
यहां कक्षा के लिए कोड है;
package com.util;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.EditText;
/**
* helper for Prompt-Dialog creation
*/
public abstract class PromptDialog extends AlertDialog.Builder implements OnClickListener {
private final EditText input;
/**
* @param context
* @param title resource id
* @param message resource id
*/
public PromptDialog(Context context, int title, int message) {
super(context);
setTitle(title);
//:TODO Display msg only if not empty
//setMessage(message);
input = new EditText(context);
setView(input);
setPositiveButton("ok", this);
setNegativeButton("cancel", this);
}
/**
* will be called when "cancel" pressed.
* closes the dialog.
* can be overridden.
* @param dialog
*/
public void onCancelClicked(DialogInterface dialog) {
dialog.dismiss();
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
if (onOkClicked(input.getText().toString())) {
dialog.dismiss();
}
} else {
onCancelClicked(dialog);
}
}
/**
* called when "ok" pressed.
* @param input
* @return true, if the dialog should be closed. false, if not.
*/
abstract public boolean onOkClicked(String input);
}
और यहां वह कोड है जिसे मैं कक्षा का उदाहरण कहता हूं;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final PromptDialog dlgName = new PromptDialog(this, R.string.enterName, R.string.enter_comment) {
@Override
public boolean onOkClicked(String input) {
// do something
mName = input;
save();
//end do some thing
return true; // true = close dialog
}
};
mTxtShiftName = (TextView) findViewById(R.id.shiftname);
mTxtShiftName.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dlgName.show();
}
});
क्या आप अपने दूसरे प्रयास पर फिर से संवाद निर्माता को बुला रहे हैं? –
मैं जो कोडिंग कर रहा हूं वह मेरे प्रश्न में कॉपी किया गया है। मुझे लगता है कि कारण हो सकता है। लेकिन मुझे नहीं पता कि इससे कैसे बचें? – SAN
जब आप बटन पर क्लिक करते हैं तो कन्स्ट्रक्टर को दो बार कॉल न करें। अपने डायलॉग कन्स्ट्रक्टर या 'ऑनपेयर डेलॉग' के साथ सिर्फ कोड के साथ 'ऑनक्रेट' में अपना संवाद बनाएं, फिर जब आप इसे दिखाना चाहते हैं तो संवाद.शो() को कॉल करें। –