構造一個能接收多位數字的輸入框

解決方案
可以通過指定Edwin editor的flags標記來限定用戶的輸入,輸入對話框的資源看起來如下:

 

Code:

DLG_LINE
{
type=EEikCtEdwin;
id=EMyQuery;

    control=EDWIN { maxlength=15; };
}
...
void CTestDlgDialog::PrepareLC(TInt aResourceId)
{
CEikDialog::PrepareLC( aResourceId );
// Dialog base class can be CAknDialog   

//CAknDialog::PrepareLC( aResourceId );
// Pick up the Editor control from the dialog
CEikEdwin* control = static_cast<CEikEdwin*>(ControlOrNull(EMyQuery));
// Set the input mode
control->SetAknEditorInputMode(EAknEditorNumericInputMode);
// Restrict the other input modes
control->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
}
上面的示例提供給用戶一個可以輸入足夠位數數字的對話框。
但是它也允許用戶輸入"*#pw+"這樣的字符——通過使用"*"或
"#"鍵,我們可以監控用戶的按鍵輸入來避免用戶輸入這些字符。
還可以顯示一個警告框提示用戶的非法輸入。
Or
Code:

RESOURCE DIALOG r_demo_data_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_DATA_QUERY
{
layout = EDataLayout;
label = ""; // prompt text
control = EDWIN
{
width = 5;
lines = 1;
maxlength = 15;
allowed_input_modes = EAknEditorNumericInputMode;
default_input_mode = EAknEditorNumericInputMode;
};
};
}
};
}

// The descriptor used for the editor
TBuf<128> text;
// The descriptor contained the prompt text for the query. The prompt // text can also be defined in the resource structure of the query
TBuf<128> prompt(_L("Enter data:"));
// create dialog instance
CAknTextQueryDialog* dlg =
new( ELeave ) CAknTextQueryDialog( text, prompt );
// Prepares the dialog, constructing it from the specified resource
dlg->PrepareLC( R_DEMO_DATA_QUERY );
// Sets the maximum length of the text editor
dlg->SetMaxLength(10);
// Launch the dialog
if (dlg->RunLD())
{
// ok pressed, text is the descriptor containing the entered text // in the editor.
}
發佈了11 篇原創文章 · 獲贊 5 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章