약간 늦었지만 내가 편집 텍스트와 체크 박스와 레이아웃 생성이 클래스 생성 비슷한 만드는 데 성공했다고 생각 :
public class CheckEditTextPreference extends DialogPreference {
protected static final String chkKey="ChkKey";
private EditText editText;
private CheckBox checkBox;
private String etValue;
private boolean chkValue;
SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
public CheckEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CheckEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected View onCreateDialogView() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(25, 0, 0, 0);
LinearLayout llChkEtPreference=new LinearLayout(getContext());
llChkEtPreference.setOrientation(LinearLayout.VERTICAL);
llChkEtPreference.setLayoutParams(layoutParams);
checkBox=new CheckBox(getContext());
editText = new EditText(getContext());
editText.setLayoutParams(layoutParams);
checkBox.setLayoutParams(layoutParams);
checkBox.setText("Disabled");
FrameLayout dialogView = new FrameLayout(getContext());
llChkEtPreference.addView(editText);
llChkEtPreference.addView(checkBox);
dialogView.addView(llChkEtPreference);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
editText.setEnabled(!isChecked);
}
});
return dialogView;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
checkBox.setChecked(getValueChk());
editText.setText(getValueEt());
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
String newValue = editText.getText().toString();
boolean newValueChk=checkBox.isChecked();
if (callChangeListener(newValue)) {
setValueEt(newValue);
}
if(callChangeListener(newValueChk))
{
setValueChk(newValueChk);
}
}
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getString(index);
}
@Override
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
setValueEt(restorePersistedValue ? getPersistedString("") : defaultValue.toString());
setValueChk(mySharedPreferences.getBoolean(chkKey, true));
}
public void setValueEt(String value) {
this.etValue = value;
persistString(this.etValue);
}
public String getValueEt() {
return this.etValue;
}
public void setValueChk(boolean value) {
this.chkValue = value;
mySharedPreferences.edit().putBoolean(chkKey, this.chkValue).apply();
}
public boolean getValueChk() {
return this.chkValue;
}
}
을 그리고 기억 (기본 설정이 점을 넣어 "그 . android.example.example.com.androiddemo "패키지의 이름)입니다 :
<android.example.example.com.androiddemo.CheckEditTextPreference
android:key="chkEtPref"
android:title="Title"/>
당신이 당신의 주요 활동이 예와 같이 뭔가를 시도 할 수있는 데이터 활용하려면 다음
을
혹시이 문제를 해결하기 위해 관리나요? 환경 설정 행에있는 체크 박스를 사용하거나 환경 설정 대화 상자에 통합하여 이처럼 사용자 정의 환경 설정을 만들려고했지만이 위치는 어디서나 찾을 수있는 유일한 참조입니다. –
@ SeanO'Toole 내 대답이 도움이되는지 확인하십시오. – theblang