我正在使用名为Mosync的Mobile Devlopment API在Mosync中开发一个Combobox(来自Label的子类),但似乎当我运行我的应用程序时,会显示组合框标签,但其内容(列表框和按钮)是没有显示。
你发生了什么事?
class ComboBox : Label
{
private:
Vector <String> options;
ComboBoxButton *button;
MAUI::ListBox *optionsBox;
public:
ComboBox( Vector <String> nOptions, MAUI::Widget *nParent )
: Label( 0, 0, 0 0, nParent ),
options(nOptions)
{
// Constructor:
button = new ComboBoxButton( "", this );
optionsBox = new MAUI::ListBox( 0, 0, 0, 0, NULL, MAUI::ListBox::LBO_VERTICAL, MAUI::ListBox::LBA_LINEAR, false );
optionsBox -> setAutoSize( true );
// Add blank element to CB
optionsBox -> add( new MAUI::Label( 0, 0, 0, 0, optionsBox, "", 0, QuickApp::defFont ) );
// Add elements to CB
for ( int i=0; i<nOptions.size(); i++ )
{
optionsBox -> add( new MAUI::Label( 0, 0, 0, 0, optionsBox, nOptions[i], 0, QuickApp::defFont ) );
}
optionsBox -> setHeight( optionsBox->getChildren()[0]->getHeight() );
this -> add( optionsBox );
this -> add( button );
}
ComboBox()
{
// Destructor:
}
void onButtonClick( bool clicked )
{
// Post: Close/Open drop down options/combo box
if ( clicked )
{
// Show all rows in the listbox
int height = 0;
for ( Vector <Widget*> rows = optionsBox->getChildren(); !rows.empty(); rows.remove(0) )
{
height += rows[0]->getHeight();
}
optionsBox -> setHeight( height );
}
else
{
// Only show the 1st row of the listbox
// Note: Ideally I would like to get the selected cell & make its position
// at the top of the LB
// But I cant find a ListBox function that allows me to either remove a
// specific row or to add a Widget at the beginning of the Listbox (not at the end)
optionsBox -> setHeight( optionsBox->getChildren()[0]->getHeight() );
}
}
};
class ComboBoxButton : Button
{
private:
ComboBox *parent;
bool clickStatus;
public: // QAButton inherits from Label & PointerListener (simple interface with virtual PointerPressEvent(), etc. functions)
ComboBoxButton( String nCaption, ComboBox *nParent )
: Button( "", (MAUI::Widget*)nParent ),
parent(nParent), clickStatus(false)
{
// Constructor:
}
void pointerPressEvent( MAPoint2d point )
{
// Post:
Point p;
p.set( point.x, point.y );
if ( this->contains(p) )
{
clickStatus = !clickStatus;
parent -> onButtonClick( clickStatus );
}
}
void pointerMoveEvent( MAPoint2d point )
{
// Post:
}
void pointerReleaseEvent( MAPoint2d point )
{
// Post:
}
};
class Button : public Label, public PointerListener
{
public:
Button( String nCaption, MAUI::Widget *nParent )
: MAUI::Label( 0, 0, 0, 0, nParent, nCaption, 0, QuickApp::defFont )
{
this -> setAutoSizeX();
this -> setAutoSizeY();
this -> setHorizontalAlignment( MAUI::Label::HA_CENTER );
this -> setVerticalAlignment( MAUI::Label::VA_CENTER );
Environment &env = Environment::getEnvironment();
env.addPointerListener( this );
}
protected:
};
答案 0 :(得分:0)
你在某个地方做了一个 - &gt; show(),我没有在你的代码中看到它。
希望这有帮助。
/托尼
PS。 MoSync 2.6有一个新版本: http://www.mosync.com/documentation/manualpages/whats-new-mosync-26-pyramid