Languages

Menu
Sites
Language
Dynamic contextMenuItem ActionListener

Hi All,

I got strucked in Context MenuItem EventListener.

Dynamically I added a HashMap To ContextMenu.

Now I didnot get how to add ActionEvent for each Item in the ContextMenu.

When I click on a button the context menu will show. when i click on perticular Item that item title has to place get and change the button name to that name.

can any one please help me.

Thanks

Rajyalakshmi

 

 

Responses

3 Replies
Gary V

Hi,

I am not sure I follow, but you create a ContextMenu in Form::OnInitializing() and add items to it with ContextMenu::AddItem(<name>, <action-id>). An action listener (IActionEventListener) defined with ContextMenu::AddActionEventListener(<listener>) will receive the standard IActionEventListener::OnActionPerformed(<context-menu>, <action-id>), just like an action from a button click or a menu. In Form::OnActionPerformed(<context-menu>, <action-id>) you can if/else check against the <action-id> and modify the Button you want with Tizen::Ui::Controls::Button::SetText(<button-title>). You can build a map from (int) <action-id> to (String) <button-title> to automate the process in OnActionPerformed().

Is that what you meant?

Gary

y Rajyalakshmi

Hi Gray,

yes. thanks for your response.

But I am facing the problem how to add action part for each single item.

for static we use on const value for each of the item, like wise how can i write action part for each item dynamically?

Thanks

Rajyalakshmi

Gary V

Perhaps something along the lines of the following?

// pseudo-code

static const int SHIFT_CONSTANT = /* mimic Tizen standards */ 400;

Form::OnInitializing()
{
    /* ArrayList* */ m_pList = new ArrayList();
	m_pList->Construct();

	m_pList->Add(new String("Sean Young"));
	m_pList->Add(new String("Halle Berry"));
	m_pList->Add(new String("Monica Bellucci"));

	for (int v = 0, s = m_pList->GetCount(); v < s; v++)
	{
		ContextMenu::AddItem(/* name */ m_pList->GetAt(v), /* <index> to <action-id> */ SHIFT_CONSTANT + v);
	}
}

Form::OnActionPerformed(<context-menu>, <action-id>)
{
	Button::SetText(m_pList->GetAt(<action-id> - SHIFT_CONSTANT));
}

Gary