사용자 지정 대화 상자 만들기에 대한 Android 설명서를 읽었습니다. 내 사용자 정의 대화 상자를 실행하는 버튼을 클릭하면 응용 프로그램이 실행됩니다. 충돌. 문제를 어떻게 해결할 수 있습니까?사용자 지정 대화 상자 시작
대화 :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayout1" android:gravity="center_vertical" android:layout_height="wrap_content" android:layout_width="fill_parent">
<CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/chkBlueTooth" android:id="@+id/chkBlueTooth" android:layout_below="@+id/chkAudio" android:layout_alignLeft="@+id/chkAudio"></CheckBox>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/chkBlueTooth" android:layout_alignLeft="@+id/chkBlueTooth" android:id="@+id/btnOK" android:text="@string/btnOK"></Button>
<CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/chkNetwork" android:id="@+id/chkNetwork" android:layout_above="@+id/chkBlueTooth" android:layout_toRightOf="@+id/chkBlueTooth"></CheckBox>
<CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/chkWifi" android:id="@+id/chkWifi" android:layout_below="@+id/chkNetwork" android:layout_alignLeft="@+id/chkNetwork" android:layout_alignRight="@+id/chkNetwork"></CheckBox>
<CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/chkAudio" android:id="@+id/chkAudio" android:layout_below="@+id/txtChoose" android:layout_alignLeft="@+id/txtChoose"></CheckBox>
</RelativeLayout>
대화의 코드 : 정적 최종 INT TIME_DIALOG_ID = 0; static final int POWER_OFF_OPTIONS = 1;
@Override protected Dialog onCreateDialog (int id) { 대화 상자; switch (id) { case TIME_DIALOG_ID : return new TimePickerDialog (this, mTimeSetListener, mHour24, mMinute, false);
case POWER_OFF_OPTIONS:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.options,
(ViewGroup)findViewById(R.id.relativeLayout1));
//Capture view elements
mChkAudio = (CheckBox) findViewById(R.id.chkAudio);
mChkBluetooth = (CheckBox) findViewById(R.id.chkBlueTooth);
mChkNetwork = (CheckBox) findViewById(R.id.chkNetwork);
mChkWifi = (CheckBox) findViewById(R.id.chkWifi);
mBtnOK = (Button) findViewById(R.id.btnOK);
mBtnOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DismissPowerOptions();
}
});
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
//return builder;
default:
dialog = null;
}
return dialog;
}
대화 상자를 표시하고 응용 프로그램 충돌이 발생 버튼 : 당신은 잘못된 개체에서 findViewById를 호출하는
mBtnPowerOffOptions.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//stuff for Options dialog
showDialog(POWER_OFF_OPTIONS);
}
});
디버거 메시지가 무엇을 findViewById를 할 수합니까 후? 코드가 작동 할 때까지 간단한 동작으로 코드를 분해해야합니다. 그런 다음 더 많은 기능을 추가하십시오. – Thorben