I am working on phonegap with android. i want to create multiple buttons at run time.
This is the function which get a list of url. So want to create a list of buttons one for each url. so whenever i press that button then i can reach to that url.’
Number of buttons depends on the number of url get by this function. Please suggest me what should i do for this to create button at run time.
this the code which are getting URLs:-
function getData(){
var output = $('#rt');
$.ajax({
url: 'http://192.168.1.214/MusicApplication/searchlatest.php',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
if(jQuery.isEmptyObject(data)){
alert("invalid user");
}else{
$.each(data, function(i,item){
alert(item.url);
//what should i do to create number of buttons according to each URL which
//are received from php page(a server page)
output.append(logi);
});
}
},
error: function(){
output.text('There was an error loading the data.');
}
});
}
Let’s say your Parent layout’s id is linearLayout.
Use an ArrayList and you could add each button dynamically and have each button with it’s own onclicklistener.
Comment if you need more clarification or information. I’d be glad to help.