android 自定義的對話框(AlertActivity)

阅读更多

Step1:

自定義的對話框Activity:

public class EthernetConfigDialog extends AlertActivity implements AdapterView.OnItemSelectedListener, DialogInterface.OnClickListener,
       AlertController.AlertParams.OnPrepareListViewListener {
    private View mView;
    static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
    private RadioButton mDhcpRadioButton,mStaticIpRadioButton;
    private LinearLayout mStaticIpConfigLinearLayout;
    private EditText mIpAddressEditText,mGatewayEditText,mNetworkPrefixLengthEditText,mSubMaskEditText,mDnsFirstEditText,mDnsSecondEditText;
    private Spinner mEthernetDevicesSpinner,mStaticProxy;
    private String tIpAddressString="",tGatewayString="",tNetworkPrefixLengthString="",tSubMaskString,tDnsFirstString="",tDnsSecondString="";
    private String mEthernetDeviceSelect="",mConnectionTypeSelect="",mStaticProxySelect = "";
    private int tEthernetDeviceIndex = 0,tNetworkPrefixLength = 0;
    private EthernetManager mEthManager;
    private IpConfiguration config;
    private static final String PROXY_NONE = "NONE";
    private static final String PROXY_STATIC = "STATIC";
    private static final String PROXY_UNASSIGNED = "UNASSIGNED";
    private static final String PROXY_PAC = "PAC";
    private static final String CONNECT_TYPE_DHCP = "dhcp_connect";
    private static final String CONNECT_TYPE_STATIC = "static_connect";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final AlertController.AlertParams p = mAlertParams;
        p.mIsSingleChoice = true;
        p.mOnItemSelectedListener = this;
        p.mView = getLayoutInflater().inflate(R.layout.ethernet_ap_dialog, null);
        mView = p.mView;
        mDhcpRadioButton = (RadioButton) mView.findViewById(R.id.ethernet_dhcp);
        mStaticIpRadioButton = (RadioButton) mView.findViewById(R.id.ethernet_static_ip);
        mStaticIpConfigLinearLayout = (LinearLayout) mView.findViewById(R.id.static_ip_config);
        mEthernetDevicesSpinner = (Spinner) mView.findViewById(R.id.ethernet_devices);
        mStaticProxy = (Spinner) mView.findViewById(R.id.ethernet_proxy);
        mIpAddressEditText = (EditText) mView.findViewById(R.id.ip_address_input);
        mGatewayEditText = (EditText) mView.findViewById(R.id.gateway_input);
        mSubMaskEditText = (EditText) mView.findViewById(R.id.submask);
        mDnsFirstEditText = (EditText) mView.findViewById(R.id.dns1_input);
        mDnsSecondEditText = (EditText) mView.findViewById(R.id.dns2_input);
        mEthManager = (EthernetManager) getApplication().getSystemService(Context.ETHERNET_SERVICE);
        mStaticProxy.setOnItemSelectedListener(this);
        getEthernetConfigSettings();
        mDhcpRadioButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mConnectionTypeSelect = CONNECT_TYPE_DHCP;
                mStaticIpConfigLinearLayout.setVisibility(View.GONE);
            }
        });

        mStaticIpRadioButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mConnectionTypeSelect = CONNECT_TYPE_STATIC;
                mStaticIpConfigLinearLayout.setVisibility(View.VISIBLE);
            }
        });
        p.mPositiveButtonText = getString(com.android.internal.R.string.ok);
        p.mPositiveButtonListener = this;
        p.mNegativeButtonText = getString(com.android.internal.R.string.cancel);
        p.mPositiveButtonListener = this;
        p.mOnPrepareListViewListener = this;
        p.mTitle = getString(R.string.ethernet_dialog_title);
        setupAlert();
    }

    //旋轉屏幕時不會onCreate()
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

 Step2:

@Override
    public void onClick(DialogInterface dialog, int which) {
        boolean positiveResult = which == DialogInterface.BUTTON_POSITIVE;
        if (positiveResult) {
            getEthernetConfigData();
        }else{

        }
    }

 

 

Step3:

 






    

        
        
        
        
            
            
        
        
            
            
            
            
            
            
            
            

            
            
            
            
        
    

 

Step4:

在AndroidManifest.xml裏添加Activity的聲明:

 


  

你可能感兴趣的:(android 自定義的對話框(AlertActivity))