Android - java.lang.IllegalArgumentException Erron when creating Dialog on 2.1 and low android

前端 未结 5 1228
既然无缘
既然无缘 2021-01-23 04:27

I\'m getting the below error message from phones that are SDK version < 8. I just released this app on the android market and prior to release my test phones were a HTC Thun

5条回答
  •  执念已碎
    2021-01-23 04:41

    I ended up having to get rid of the dialog = null. I also had to move the switching between activeTextView from onCreateDialog(int id) to onPrepareDialog(int id, Dialog dialog).

    Below is the updated code.

        @Override
    protected Dialog onCreateDialog(int id) {
        super.onCreateDialog(id);
        Dialog dialog = null;
    
        switch(id){
        case 1:
            dialog = new CustomCalcDialog(this);
            dialog.setTitle("Enter Shipping %");
            break;
        case 2:
            dialog = new CustomCalcDialog(this);
            dialog.setTitle("Enter Tax Rate");
            break;
        case 3:
            dialog = new CustomCalcDialog(this);
            dialog.setTitle("Enter Commission %");
            break;
        case 4:
            dialog = new CustomCalcDialog(this);
            dialog.setTitle("Calculate Subtotal");
            break;
        case 5:
            dialog = new CustomCalcDialog(this);
            dialog.setTitle("Additional Shipping");
            break;
        case 6:
            dialog = new BackgroundOptionsDialog(this);
            dialog.setTitle("Choose Background:");
            break;
        }
        return dialog;
    }
    
    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        super.onPrepareDialog(id, dialog);
    
        switch(id){
        case 1:         
            activeTextView = shippingPercent;
            break;
        case 2:
            activeTextView = taxPercent;
            break;
        case 3:
            activeTextView = commissionPercent;
            break;
        case 4:
            activeTextView = productSubtotal;
            break;
        case 5:
            activeTextView = addShipping;
            break;
        }
    }
    

提交回复
热议问题