Just getting started with PhoneGap and looking for a way to create the kind of dialog shown here: http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList but only found notification.alert and notification.confirm - but there must be some way to create a list dialog?
2 Answers
I created a Phonegap Android Plugin for this. When working with Phonegap Android plugin, you need to do:
- Add the Java file in the /src folder
- Update your /res/xml/config.xml for your Phonegap plugin settings
- Call your the plugin with cordova.exec() in your HTML/Javascript
Do check the Phonegap plugin development if you need extra guide on that.
You can download my AlertDialog List plugin at github.
Assuming you have your Phonegap Android Eclipse setup properly, together with the plugin, in your HTML/Javascript, you can just call something like this.
<script>
var fruitlist = [
"The Fruit List Title", // this is the title
"Orange",
"Apple",
"Watermelon",
"Papaya",
"Banana",
"Pear"
];
function showlist(thelist) {
cordova.exec(
function(listitem) {
alert( "You selected "+ thelist[listitem] );
},
function(error) {
alert("Error Occured");
}, "AlertList", "alertlist", thelist );
}
</script>
<a href="javascript:showlist(fruitlist)">Pick your fruit</a>
I think I should also remind you that you need to load cordova properly in your HTML/Javascript. We do that by listening to deviceready event. Otherwise, cordova.exec won't work. This is like the $(document).ready in jQuery.
document.addEventListener("deviceready", your_function, false);
AlertDialog List Phonegap Android Plugin