Hi all, in this example I will show you how to use
PhoneGap with
jQuery Mobile Architecture .
Well to use jQuery Mobile Architecture you need to embed following css file and js file. And remember one thing you have maintain the order.
Now create a file called index.html and paste the following code inside that file. Hare I have used the concept of jQuery Mobile Architecture, a single html page with multiple div element.
Connected
Now add the following script in side your index.html file.
Well in this script I have used a google api i.e. "https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q= " this api is used to convert the xml output to JSON output.
$(document).on('pagebeforeshow', '#one', function() {
$('.news-chanel').on('click', function(e, data) {
rss_url_map = {
'cnn-top-stories': 'https://rss.cnn.com/rss/edition.rss',
'bbc-top-stories': 'https://feeds.bbci.co.uk/news/rss.xml',
'ibn-top-stories': 'https://ibnlive.in.com/ibnrss/top.xml',
'cnn-world': 'https://rss.cnn.com/rss/edition_world.rss',
'bbc-world': 'https://feeds.bbci.co.uk/news/world/rss.xml',
'ibn-world': 'https://ibnlive.in.com/ibnrss/rss/world/world.xml',
'cnn-world-business': 'https://rss.cnn.com/rss/edition_business.rss',
'bbc-world-business': 'https://feeds.bbci.co.uk/news/business/rss.xml',
'ibn-world-business': 'https://ibnlive.in.com/ibnrss/rss/business/business.xml',
'cnn-technology': 'https://rss.cnn.com/rss/edition_technology.rss',
'bbc-technology': 'https://feeds.bbci.co.uk/news/technology/rss.xml',
'ibn-technology': 'https://ibnlive.in.com/ibnrss/rss/tech/tech.xml',
'cnn-world-soprts': 'https://rss.cnn.com/rss/edition_sport.rss',
'bbc-world-soprts': 'https://news.bbc.co.uk/sport1/hi/help/rss/default.stm',
'ibn-world-soprts': 'https://ibnlive.in.com/ibnrss/rss/sports/sports.xml',
};
url = rss_url_map[this.id];
$.ajax({
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: "jsonp",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function() {
$.mobile.showPageLoadingMsg(true);
},
complete: function() {
$.mobile.hidePageLoadingMsg();
},
success: function(result) {
ajax.jsonResult = result;
$.mobile.changePage("#two");
},
error: function(request, error) {}
});
});
});
$(document).on('pagebeforeshow', '#two', function() {
ajax.parseJSONP(ajax.jsonResult);
});
var ajax = {
jsonResult: null,
parseJSONP: function(result) {
feedUrl = result.responseData.feed.feedUrl;
pgtitle = result.responseData.feed.title;
$("#pgtitle").text(pgtitle).trigger('create');
htmlData = '';
entriesList = result.responseData.feed.entries;
$.each(entriesList, function(index, value) {
title = value.title;
link = value.link;
publishedDate = value.publishedDate;
contentSnippet = value.contentSnippet;
content = value.content;
htmlData += ' ' + title + ' ' + contentSnippet + '
';
});
$('#newsdata').empty();
$("#newsdata").html(htmlData);
$('#newsdata').listview('refresh');
}
}
And you final code will be like following.
Connected
Now create an android project as I explained in my previous post and put this index.html file over there and run your project and after that you will get the output like following.
No comments:
Post a Comment