http://wiki.forum.nokia.com/index.php/Tips_of_CAknForm
1.动态更新弹出列表
CAknForm上使用的弹出控件是CAknPopupFieldText,但它只提供了查询列表项的方法(const MDesCArray* MdcArray() const;),由于是常量对象,所以不能修改其中的内容。另外还有一个设置列表项的方法SetQueryValueL(MAknQueryValue* aValue)被置为私有方法,同样不能使用。通过查看它的基类CAknPopupField发现SetQueryValueL()是一个公有方法,经过试验证明可以使用它动态设置弹出列表项,下面列出代码:
class CTestForm : public CAknForm
{
………………
private:
CDesCArray *iItemArray;
CAknQueryValueTextArray *iTextArray;
CAknQueryValueText *iQueryValText;
CAknPopupFieldText *iPopupCtrl;
TFromInfo iFormInfo;
}
//设置新的列表项
void CTestForm::PreLayoutDynInitL()
{
CAknForm::PreLayoutDynInitL();
iPopupCtrl = static_cast <CAknPopupFieldText*> (ControlOrNull(EPopupCtrlId));
CAknPopupField* popupFieldText = iPopupCtrl;
if (popupFieldText)
{
iItemArray = new (ELeave) CDesCArrayFlat( 6 );
iItemArray->AppendL(_L("NewItem1"));
iItemArray->AppendL(_L("NewItem2"));
iItemArray->AppendL(_L("NewItem3"));
iItemArray->AppendL(_L("NewItem4"));
iTextArray = CAknQueryValueTextArray::NewL();
iTextArray->SetArray( *iItemArray );
iQueryValText = CAknQueryValueText::NewL();
iQueryValText->SetArrayL( iTextArray );
iQueryValText->SetCurrentValueIndex( 0 );
popupFieldText->SetQueryValueL( iQueryValText );
}
//获取列表项的索引和值
//因为是能过基类更新的列表项,所以不能使用CAknPopupFieldText的CurrentValueIndex()
//和CurrentValueTextLC()方法获取数据,它们返回的还是原有列表项的内容。
TBool CTestForm::SaveFormDataL()
{
if( iPopupCtrl )
{
iFormInfo.iPopupIndex = iQueryValText->CurrentValueIndex();
iFormInfo.iPopupVal.Copy( iItemArray->MdcaPoint(pos) );
}
return ETrue;
}
//释放对象
// CAknQueryValueTextArray的SetArray(),CAknQueryValueText的 SetArrayL()和
//CAknPopupField的SetQueryValueL()这些方法并不传递对象的所有权,所以需要我们负责//释放分配的对象
CTestForm::~CTestForm()
{
delete iItemArray;
delete iTextArray;
delete iQueryValText;
}
2.关联列表项与其它项
有时当用户选择列表项后,我们需要得到这个事件并更新Form上其它控件的内容。获取这个事件可以通过重载CAknForm的HandleControlStateChangeL()方法来实现:
//From CAknForm
void CTestForm::HandleControlStateChangeL(TInt aControlId)
{
CAknForm::HandleControlStateChangeL( aControlId );
if( aControlId == EPopupCtrlId )
{
TInt index = iQueryValText->CurrentValueIndex();
//更新Form上某个编辑框的内容
iEdwin->SetTextL( &(iItemArray->MdcaPoint(index)) );
iEdwin->DrawNow();
}
}
http://www.devdiv.com/thread-24259-1-1.html
好吧,不知是这里高手不屑于看着个帖还是问题太非主流,还是公司的老前辈帮我找到了方法,我把方案贴出来,自己给自己结贴了……
RESOURCE FORM r_memberlistedit_form
{
flags = EEikFormUseDoubleSpacedFormat | EEikFormEditModeOnly;
items =
{
DLG_LINE
{
type = EEikCtEdwin;
prompt = qtn_bawlist_contexer;
id = EMemberListFormName;
itemflags = EEikDlgItemTakesEnterKey | EEikDlgItemOfferAllHotKeys;
control = EDWIN
{
flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable;
width = 1;
lines = 2;
maxlength = 64;
};
},
DLG_LINE
{
type = EEikCtEdwin;
prompt = qtn_bawlist_phonenum;
id = EMemberListFormNum;
itemflags = EEikDlgItemTakesEnterKey | EEikDlgItemOfferAllHotKeys;
control = EDWIN
{
flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable;
width = 1;
lines = 2;
maxlength = 20;
avkon_flags = EAknEditorFlagSupressShiftMenu;
default_input_mode = EAknEditorNumericInputMode;
};
},
DLG_LINE
{
prompt = qtn_bawlist_rules;
id = EMemberListFormRule;
type = EAknCtPopupFieldText;
itemflags = EEikDlgItemTakesEnterKey | EEikDlgItemOfferAllHotKeys;
control = POPUP_FIELD_TEXT
{
popupfield = POPUP_FIELD
{
width = 30;
};
active = 1;
textarray = r_bawlist_rulelist;
};
}
};
}
RESOURCE ARRAY r_bawlist_rulelist
{
items =
{
LBUF { txt = qtn_bawlist_rules1; },
LBUF { txt = qtn_bawlist_rules2; },
LBUF { txt = qtn_bawlist_rules3; }
};
}
最后这个popuplist仅当此form处于editable = true时有效