Android Dialog(對話框中獲取輸入框的內容) ,直接上代碼
[java]
- final EditText et = new EditText(this);
- et.setText(mSharedPreferences.getString("ipadd", "127.0.0.1"));
- //獲取ip而已,不用在乎
- new AlertDialog.Builder(this).setTitle("請輸入IP地址")
- .setIcon(android.R.drawable.ic_dialog_info).setView(et)
- .setPositiveButton("確定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface arg0, int arg1) {
- //數據獲取
- //Toast.makeText(TestTabActivity.this, et.getText().toString(),
- // Toast.LENGTH_LONG).show();
- mEditor.putString("ipadd", et.getText().toString());
- //關鍵在這兒,獲取輸入框的數據,原來很簡單!!
- mEditor.commit();
- }
- }).setNegativeButton("取消", null).show();