您的位置:首页 > 运维架构

CAknPopupFieldText在表单中动态创建及动态增加数组列表的操作

2008-05-29 09:18 525 查看
折腾了一天终于把CAknPopupFieldText在表单中动态创建及动态增加数组列表的操作搞定,主要分为以下几步:

1、定义资源文件

RESOURCE ARRAY r_settings_choice_std
{
items =
{
LBUF
{
txt = qtn_appl_test;
},
LBUF
{
txt=qtn_appl_help;
}
};
}

RESOURCE POPUP_FIELD_TEXT r_popup_dynamic_question {
popupfield = POPUP_FIELD {
width = 10;
};
textarray = r_settings_choice_std;
active = 0;
}

2、在CAknForm字类中增加变量

CDesCArray *iItemArray;
CAknQueryValueTextArray *iTextArray;
CAknQueryValueText *iQueryValText;

3、PreLayoutDynInitL()函数中增加以下代码

//增加一个CAknPopupFieldText控件

HBufC* buftemp=StringLoader::LoadLC(QTN_NAVI_LABEL_CONTACTGROUPVIEW);
CCoeControl* popupControl = CreateLineByTypeL(*buftemp, ActivePageId(), iNewItemId, EAknCtPopupFieldText, NULL );
CAknPopupFieldText* popupQuestion = static_cast<CAknPopupFieldText*>(popupControl);
TResourceReader reader;

CEikonEnv::Static()->CreateResourceReaderLC(reader, R_POPUP_DYNAMIC_QUESTION);
popupQuestion->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(2); //reader
Line(iNewItemId)->SetTakesEnterKey(ETrue);
Line(iNewItemId)->SetOfferHotKeys(ETrue);

//动态生成CAknPopupFieldText里显示的数组内容

CAknPopupField* popupField =popupQuestion;
int ncount=iContactDb->GetGroupCount();
iItemArray = new (ELeave) CDesCArrayFlat(ncount);
for(int i=0;i<ncount;i++)
{
iItemArray->AppendL(iContactDb->GetGroupAt(i));
}

iTextArray = CAknQueryValueTextArray::NewL();
iTextArray->SetArray( *iItemArray );
iQueryValText = CAknQueryValueText::NewL();
iQueryValText->SetArrayL( iTextArray );
iQueryValText->SetCurrentValueIndex( 0 );
popupField->SetQueryValueL( iQueryValText );

iNewItemId++;

4、在析构函数中删除动态生成的内容

if(iItemArray)
{
iItemArray->Reset();
delete iItemArray;
iItemArray=NULL;
}
if(iTextArray)
{
delete iTextArray;
iTextArray=NULL;
}
if(iQueryValText)
{
delete iQueryValText;
iQueryValText=NULL;
}

5、读取相关选择时可使用

HBufC* buf=iQueryValText->CurrentValueTextLC();

6、如果只需要动态生成控件,而不需要动态生成里边显示的数组时,可把数组在资源文件中定义,在PreLayoutDynInitL()中加下边一段代码即可

HBufC* buftemp=StringLoader::LoadLC(QTN_NAVI_LABEL_CONTACTGROUPVIEW);
CCoeControl* popupControl = CreateLineByTypeL(*buftemp, ActivePageId(), iNewItemId, EAknCtPopupFieldText, NULL );
CAknPopupFieldText* popupQuestion = static_cast<CAknPopupFieldText*>(popupControl);
TResourceReader reader;

CEikonEnv::Static()->CreateResourceReaderLC(reader, R_POPUP_DYNAMIC_QUESTION);
popupQuestion->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(2); //reader
Line(iNewItemId)->SetTakesEnterKey(ETrue);
Line(iNewItemId)->SetOfferHotKeys(ETrue);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: