0

以下のコードボタンに示すように、ラジオボタンのグループがあります。各ラジオ ボタンをクリックすると、下の図に示すように、別のダイアログが必要です。ラジオ ボタンごとに 1 つです。これらはダイアログ内にある必要があります。どうすればいいですか? 最後に必要なのは、これらのカスタム ダイアログを生成することだけです。どうすればそれを行うことができますか?

カスタム ダイアログ ビュー

また、ヌルポインタ例外が発生しています。どうすれば解決できますか??

public class Availability extends Activity implements OnClickListener,
        OnCheckedChangeListener {
    ToggleButton override;
    TextView status;
    Button Overridestatus;
    CharSequence[] choice = { "RemoteOffice", "Office", "Personal mobile",
            "Home", "Mobile", "Temporary", "Do not Disturb",
            "Working Remotely", "Non work day", "Work Day" };
    RadioGroup timeperiod;
    TimePicker timePicker;
    int hour, minute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.availability);
        override = (ToggleButton) findViewById(R.id.tbOver);
        override.setOnClickListener(this);
        status = (TextView) findViewById(R.id.tvstatus);
        Overridestatus = (Button) findViewById(R.id.bstatus);
        Overridestatus.setOnClickListener(this);
        timeperiod = (RadioGroup) findViewById(R.id.rgtimeperiod);
        timeperiod.setOnCheckedChangeListener(this);
        timePicker = (TimePicker) findViewById(R.id.timePicker);
        timePicker.setIs24HourView(true);

    }

    public void onClick(View view) {
        // TODO Auto-generated method stub
        switch (view.getId()) {
        case R.id.tbOver:

            if (override.isChecked()) {

                status.setText("Override");
                Overridestatus.setText("Personal Mobile");

            } else {
                status.setText("Currently");
                Overridestatus.setText("Use Schedule - Do Not Disturb");

            }
            break;

        case R.id.bstatus:

        {
            if (override.isChecked()) {
                showDialog(0);
            }
        }

            break;
        case R.id.rhrandmin:
        }
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        switch (id) {
        case 0:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Select System Server");
            builder.setIcon(R.drawable.ic_btn_round_more_normal);
            builder.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            // TODO Auto-generated method stub
                            Intent menu = new Intent(Availability.this,
                                    MenuScreen.class);
                            startActivity(menu);

                        }
                    });
            builder.setNegativeButton("CANCEL",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                        }
                    });

            builder.setSingleChoiceItems(choice, -1,
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int item) {
                            // TODO Auto-generated method stub

                        }
                    });

            builder.create();
            builder.show();
            break;
        case 2:
             new TimePickerDialog(this, mTimeSetListener, hour, minute,false);
            break;
        }

        return null;

    }

    private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minuteOfHour) {
            hour = hourOfDay;
            minute = minuteOfHour;
            Toast.makeText(getBaseContext(),
                    "You have selected : " + hour + ":" + minute,
                    Toast.LENGTH_SHORT).show();
        }
    };

    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // TODO Auto-generated method stub
        switch (checkedId) {
        case R.id.ridefinate:

            break;

        case R.id.rdays:

            break;
        case R.id.rhrandmin:
        //  showDialog(2);
            break;
        case R.id.rtilldate:
             showDialog(1);
            break;
        }
    }

}

ログキャット

10-16 19:16:16.567: E/AndroidRuntime(1137): FATAL EXCEPTION: main
10-16 19:16:16.567: E/AndroidRuntime(1137): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.avst.callxpressmobile/com.example.avst.callxpressmobile.Availability}: java.lang.NullPointerException
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.os.Looper.loop(Looper.java:137)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at java.lang.reflect.Method.invokeNative(Native Method)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at java.lang.reflect.Method.invoke(Method.java:511)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at dalvik.system.NativeStart.main(Native Method)
10-16 19:16:16.567: E/AndroidRuntime(1137): Caused by: java.lang.NullPointerException
10-16 19:16:16.567: E/AndroidRuntime(1137):     at com.example.avst.callxpressmobile.Availability.onCreate(Availability.java:47)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.Activity.performCreate(Activity.java:5008)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-16 19:16:16.567: E/AndroidRuntime(1137):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-16 19:16:16.567: E/AndroidRuntime(1137):     ... 11 more
4

1 に答える 1

0

Android には 2 つの標準ダイアログが用意されています。DatePickerDialogTimePickerDialog。カスタム ダイアログを作成する場合は、このガイドを参照してください。

于 2012-10-16T07:17:29.043 に答える