ListView ListView = Listview::create (); --Create a list
Listview->setdirection (Ui::scrollview::D irection::vertical); --set list orientation
Listview->setbounceenabled (TRUE); --Set stretch
Listview->setbackgroundimage ("Cocosui/green_edit.png"); --Set background image
Listview->setbackgroundimagescale9enabled (TRUE); --set whether to allow nine lattice
Listview->setcontentsize (Size (a); --Set size
Listview->setposition (VEC2 ());
Listview->addeventlistener ((Ui::listview::cclistviewcallback) Cc_callback_2 (class name:: Callback function 1, this)); //Register event handler function
Listview->addeventlistener ((Ui::listview::ccscrollviewcallback) Cc_callback_2 (class Name: callback function 2, this)); //Register event handler function
void class Name:: Callback function 1 (REF * psender, Listview::eventtype type) --Note the parameter type here
{
Switch (type)
{
Case Cocos2d::ui::listview::eventtype::on_selected_item_start:
ListView * ListView = Static_cast (ListView *) (Psender);
Listview->getcurselectedindex ();
Break
Case Cocs2d::ui::listview::eventtype::on_selected_item_end:
ListView * ListView = Static_cast (ListView *) (Psender);
Listview->getcurselectedindex ();
Break
Default
Break
}
}
void class Name:: Callback function 2 (REF * psender, Ui::scrollview::eventtype type)
{
Switch (type)
{
Case Ui::scrollview::eventtype::scroll_to_bottom:
Break
Case Ui::scrollview::eventtype::scroll_to_top:
Break
Default
Break
}
}
Layout * Default _item = Layout::create (); //Create model
Listview->setitemmodel (Default_item); //Setup Model
Listview->pushbackdefaultitem (); //Add default Element
Listview->insertdefaultitem (index); //insert default Element
Layout * Custom_item = Layout::create ();
Listview->addchild (Custom_item); //Add regular elements
Listview->insertcustomitem (Custom_item, index) //Insert Regular element
vector<widget*>& items = Listview->getitems (); Returns the container that holds the element
widget* item = Listview->getitem (i); //Get an element of an index
ssize_t index = Listview->getindex (item); //Gets the index of an element
Listview->removechildbytag (1); //functions that inherit from Ccnode
Listview->removeitem (items_count-1); //Delete an element of an index
Listview->setgravity (listview::gravity::center_vertical); Set Gravity
Listview->setitemsmargin (2.0f); //Change the boundary between two elements
Cocos2d-x3.3final (1) ListView Common member function (c + +)