The current version of function “CCMessageBox” for Android ,can only show one style AlertDialog(the dialog has only one PositiveButton “OK”):
cpp layer java layer
^ ^
CCMessageBox() —>showMessageJNI() —>showMessageBox~~>showDialog
and what showDialog does is new A AlertDialog has one PositiveButton OK
<pre>
private void showDialog{
Dialog dialog = new AlertDialog.Builder
.setTitle
.setMessage
.setPositiveButton
{
public void onClick{
}
}).create;
dialog.show;
}
</pre>
Frankly speaking , this dialog is not enough for me ,because it is too simple.
What if I want to show a dialog to let user choose from two button?
/——————~~| Quit? |
| — — |
| yes no |
|—- —- |
or:
/——————| open web site | —- |
| — — |
| no open it |
|—
forgive my pool drawing
To reach my goal I think do some stuff at these steps will be good:
1.expand the CCMessageBox and showMessageBoxJNI :
CCMessageBox(String title, String message)
—>
CCMessageBox(int type,String title, String message,String payload)
showMessageBoxJNI(const char * pszMsg, const char * pszTitle)
—>
showMessageBoxJNI(int type,const char * pszMsg, const char * pszTitle,const char* pszPayload)
2.makes Cocos2dxActivity’s private method showDialog protected:
private void showDialog(String title, String message)
—>
protected void showDialog(String title, String message)
why i do this is to make the Cocos2dxActivity’s child can override showDialog implement:
Cocos2dxActivity’s child ,generally is your main gameAcitivy:
@Override
protected void showDialog(int type,String title, String message,String payload) {
//custom your own dialog use upon Parameters or ignore them
}
if you do not want to custom your alert dialog, you can just jump this!
3.done
Here is a Use Cases:
cpp layer:
int kMessageType_open_a_url_yes_no = 0
CCMessageBox(kMessageType_open_a_url_yes_no,"open our site?","only title"," www.cocos2d-x.org")
java layer:
@Override
protected void showDialog(int type,String title, String message,String payload) {
if(type ==0){
//new AlertDialog
// dialog.setMessage,set Title
// onClick,do new intent(Action.view,Uri.parse(payload))
}
}
that’s all