Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 05:15, 23 December 2007.

Tips of CAknForm

From Forum Nokia Wiki

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();
}
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
Validation of datafield!! symbee Symbian User Interface 25 2006-10-17 07:03
Record video and grabbing frame from video Tobias_80 Mobile Java Media (Graphics & Sounds) 4 2007-08-16 12:01
Loading Nokia 6165i and 6265i handsets for testing - any tips? Mario.Lopez General Discussion 5 2008-01-17 23:16
How to exit a form ? vnleeds Symbian User Interface 6 2008-03-20 12:45
isoj2me: isometric engine for j2me... realdarkwave Mobile Java Media (Graphics & Sounds) 4 2004-05-29 13:25
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX