Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Tips of CAknForm

From Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台:
Symbian

文章
beover1984 在 23 Dec 2007 创建
最后由 hamishwillee 在 08 May 2013 编辑

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();
}
}
This page was last modified on 8 May 2013, at 00:03.
291 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×