アラート ダイアログ (下部にチェックボックスあり) を作成し、[設定] をクリックして起動します。最初の警告ダイアログは正常に起動しましたが、2 回目は次の例外が発生しました:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
MainActivity.java
final View checkBoxView = View.inflate(this, R.layout.checkbox, null); /*to inflate dialog with checkbox */
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
System.out.println("******** CheckBox Clicked *********");
/* Save to shared preferences */
}
});
checkBox.setText("Use by default for this action");
Preference pref = (Preference) findPreference("preference");
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
final CharSequence[] items = {"BT Smart Settings by ABC",
"BT Smart Settings by XYZ",
"BT Smart Settings by DEFAULT"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Complete action using");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
System.out.println("************* clicked-item :"+item);
}
});
builder.setView(checkBoxView);
AlertDialog alert = builder.create();
alert.show();
return false;
}
});
この点でどんな助けでも大歓迎です。