In Android RSS Reader Application using SQLite Part 1 we completed creating required classes. In this part we are starting with designing the application.

Download Code

6. Designing the Header

The application header has a gradient background color and a plus button on the right side. So create the required xml files to get header layout.

I created a plus button and logo using photoshop in 72x72px, 48x48px and 36x36px dimensions and placed under drawable-hdpi, drawable-mdpi and drawable-ldpi folder.

rss parser icon design

Create a new xml file under drawable folder and name it as header_gradient.xml and header.xml paste the following code.

header_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#db0000"
        android:centerColor="#c50300"
        android:endColor="#b30500"
        android:angle="270"/>
</shape>

header.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutHeader"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_alignParentTop="true"
    android:background="@layout/header_gradient"
    android:orientation="horizontal">
    
    <!-- Logo -->
    <ImageView android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dip"/>

    <!-- Plus Button -->

    <ImageButton
        android:id="@+id/btnAddSite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dip"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/plus"
        android:layout_centerVertical="true" />

</RelativeLayout>

The above xml will generate following header layout.

rss_parser_header

7. Displaying all websites in listview (from SQLite)

In our application the first screen will display all the websites in listview from SQLite database.

Open your main activity file (in my case AndroidRSSReaderApplicationActivity.java) and type the following code. In the following code

-> First a background thread is called to load the websites from sqlite table.
-> In background thread websites are displayed in listview.
-> Also the header plus button has click event which will launch add new website activity.
-> If you long press on list item it will show you context menu with delete option.

Create a xml file called site_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff">
    
    <!-- Header -->
    <include layout="@layout/header"/>
 
    <ListView
        android:id="@+id/list"
        android:layout_below="@id/layoutHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#bababa"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" 
        android:background="#ffffff"
        android:cacheColorHint="#00000000"/>
 
</RelativeLayout>

Also create an xml file listview single row
site_list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:padding="5dip">
    
    <!-- SQLite row id / hidden by default -->
    <TextView android:id="@+id/sqlite_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"/>
 
    <!-- web site title -->
    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="8dip"
        android:paddingLeft="8dip"
        android:paddingBottom="4dip"
        android:textSize="18dip"
        android:textColor="#1a1a1a" />
 
    <!-- web site url -->
    <TextView android:id="@+id/link"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingLeft="8dip"
        android:paddingBottom="6dip"
        android:textSize="15dip"
        android:textColor="#c00300"
        android:layout_below="@id/title"/>
    
    <!-- Right end Arrow -->
     <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"/>
 
</RelativeLayout>

AndroidRSSReaderApplicationActivity.java

package com.androidhive.rssreader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class AndroidRSSReaderApplicationActivity extends Activity {
	// Progress Dialog
	private ProgressDialog pDialog;

	// Array list for list view
	ArrayList<HashMap<String, String>> rssFeedList;

	RSSParser rssParser = new RSSParser();

	RSSFeed rssFeed;
	
	// button add new website
	ImageButton btnAddSite;
	
	// array to trace sqlite ids
	String[] sqliteIds;

	public static String TAG_ID = "id";
	public static String TAG_TITLE = "title";
	public static String TAG_LINK = "link";
	
	// List view
	ListView lv;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.site_list);
		
		btnAddSite = (ImageButton) findViewById(R.id.btnAddSite);
		
		
		// Hashmap for ListView
		rssFeedList = new ArrayList<HashMap<String, String>>();
		
	
		/**
		 * Calling a background thread which will load 
		 * web sites stored in SQLite database
		 * */
		new loadStoreSites().execute();
		
		// selecting single ListView item
        lv = (ListView) findViewById(R.id.list); 
 
        // Launching new screen on Selecting Single ListItem
        lv.setOnItemClickListener(new OnItemClickListener() {
 
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String sqlite_id = ((TextView) view.findViewById(R.id.sqlite_id)).getText().toString();
                // Starting new intent
                Intent in = new Intent(getApplicationContext(), ListRSSItemsActivity.class);
                // passing sqlite row id
                in.putExtra(TAG_ID, sqlite_id);
                startActivity(in);
            }
        });
		
		
        /**
         * Add new website button click event listener
         * */
		btnAddSite.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				Intent i = new Intent(getApplicationContext(), AddNewSiteActivity.class);
				// starting new activity and expecting some response back
				// depending on the result will decide whether new website is
				// added to SQLite database or not
                startActivityForResult(i, 100);
			}
		});
	}
	
	/**
	 * Response from AddNewSiteActivity.java
	 * if response is 100 means new site is added to sqlite
	 * reload this activity again to show 
	 * newly added website in listview
	 * */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }
    }
    
    /**
     * Building a context menu for listview
     * Long press on List row to see context menu
     * */
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
      if (v.getId()==R.id.list) {
        menu.setHeaderTitle("Delete");
        	menu.add(Menu.NONE, 0, 0, "Delete Feed");
      }
    }
    
    /**
     * Responding to context menu selected option
     * */
    @Override
    public boolean onContextItemSelected(MenuItem item) {
      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
      int menuItemIndex = item.getItemId();
      // check for selected option
      if(menuItemIndex == 0){
    	  // user selected delete
    	  // delete the feed
    	  RSSDatabaseHandler rssDb = new RSSDatabaseHandler(getApplicationContext());
    	  WebSite site = new WebSite();
    	  site.setId(Integer.parseInt(sqliteIds[info.position]));
    	  rssDb.deleteSite(site);
    	  //reloading same activity again
    	  Intent intent = getIntent();
          finish();
          startActivity(intent);
      }
      
      return true;
    }

	/**
	 * Background Async Task to get RSS data from URL
	 * */
	class loadStoreSites extends AsyncTask<String, String, String> {

		/**
		 * Before starting background thread Show Progress Dialog
		 * */
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(
					AndroidRSSReaderApplicationActivity.this);
			pDialog.setMessage("Loading websites ...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();
		}

		/**
		 * getting all stored website from SQLite
		 * */
		@Override
		protected String doInBackground(String... args) {
			// updating UI from Background Thread
			runOnUiThread(new Runnable() {
				public void run() {
					RSSDatabaseHandler rssDb = new RSSDatabaseHandler(
							getApplicationContext());
					
					// listing all websites from SQLite
					List<WebSite> siteList = rssDb.getAllSites();
					
					sqliteIds = new String[siteList.size()];
					
					// loop through each website
					for (int i = 0; i < siteList.size(); i++) {
						
						WebSite s = siteList.get(i);
						
						// creating new HashMap
						HashMap<String, String> map = new HashMap<String, String>();

						// adding each child node to HashMap key => value
						map.put(TAG_ID, s.getId().toString());
						map.put(TAG_TITLE, s.getTitle());
						map.put(TAG_LINK, s.getLink());

						// adding HashList to ArrayList
						rssFeedList.add(map);
						
						// add sqlite id to array
						// used when deleting a website from sqlite
						sqliteIds[i] = s.getId().toString();
					}
					/**
					 * Updating list view with websites
					 * */
					ListAdapter adapter = new SimpleAdapter(
							AndroidRSSReaderApplicationActivity.this,
							rssFeedList, R.layout.site_list_row,
							new String[] { TAG_ID, TAG_TITLE, TAG_LINK },
							new int[] { R.id.sqlite_id, R.id.title, R.id.link });
					// updating listview
					lv.setAdapter(adapter);
					registerForContextMenu(lv);
				}
			});
			return null;
		}

		/**
		 * After completing background task Dismiss the progress dialog
		 * **/
		protected void onPostExecute(String args) {
			// dismiss the dialog after getting all products
			pDialog.dismiss();
		}

	}
}

The above activity will produce following screen which will list all the websites in listview (If you have any websites stored in websites table).

rss parser list all websites

8. Adding new website to SQLite

Create new activity and layout which allows user to add new website to application. The screen will be launched if user clicks on plus button in header.

Create a xml layout to called add_site.xml

add_site.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#ffffff">
    
    <TextView android:id="@+id/lblUrl" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Enter URL (http://abc.com)"
        android:textColor="#c50300"
        android:padding="10dip"
        android:textStyle="bold"/>
    
    <EditText android:id="@+id/txtUrl" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dip"
        android:layout_marginLeft="10dip"
        android:layout_below="@id/lblUrl"
        android:inputType="textUri"
        android:hint="Enter website url"
        android:singleLine="true"/>
    
    <Button android:id="@+id/btnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtUrl"
        android:text="Submit" 
        android:layout_marginTop="8dip"
        android:layout_marginLeft="8dip"/>
    
    <Button android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/btnSubmit"
        android:layout_below="@id/txtUrl"
        android:text="Cancel" 
        android:layout_marginTop="8dip"
        android:layout_marginLeft="8dip"
        android:windowSoftInputMode="stateVisible|adjustPan"/>
    
    <TextView android:id="@+id/lblMessage" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ff0000"
        android:padding="10dip"
        android:layout_marginTop="15dip"
        android:layout_below="@id/btnSubmit"/>

</RelativeLayout>

Also create a new class file and name it as AddNewSiteActivity.java and type following code. In the following

-> Website url is validated once user click on submit button.
-> If it is a valid url a background thread is called to get rss link from url.
-> Once RSS url found a new row will be created in SQLite websites table.

AddNewSiteActivity.java

package com.androidhive.rssreader;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddNewSiteActivity extends Activity {

	Button btnSubmit;
	Button btnCancel;
	EditText txtUrl;
	TextView lblMessage;

	RSSParser rssParser = new RSSParser();

	RSSFeed rssFeed;

	// Progress Dialog
	private ProgressDialog pDialog;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_site);

		// buttons
		btnSubmit = (Button) findViewById(R.id.btnSubmit);
		btnCancel = (Button) findViewById(R.id.btnCancel);
		txtUrl = (EditText) findViewById(R.id.txtUrl);
		lblMessage = (TextView) findViewById(R.id.lblMessage);

		// Submit button click event
		btnSubmit.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				String url = txtUrl.getText().toString();

				// Validation url
				Log.d("URL Length", "" + url.length());
				// check if user entered any data in EditText
				if (url.length() > 0) {
					lblMessage.setText("");
					String urlPattern = "^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";
					if (url.matches(urlPattern)) {
						// valid url
						new loadRSSFeed().execute(url);
					} else {
						// URL not valid
						lblMessage.setText("Please enter a valid url");
					}
				} else {
					// Please enter url
					lblMessage.setText("Please enter website url");
				}

			}
		});

		// Cancel button click event
		btnCancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}

	/**
	 * Background Async Task to get RSS data from URL
	 * */
	class loadRSSFeed extends AsyncTask<String, String, String> {

		/**
		 * Before starting background thread Show Progress Dialog
		 * */
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(AddNewSiteActivity.this);
			pDialog.setMessage("Fetching RSS Information ...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();
		}

		/**
		 * getting Inbox JSON
		 * */
		@Override
		protected String doInBackground(String... args) {
			String url = args[0];
			rssFeed = rssParser.getRSSFeed(url);
			Log.d("rssFeed", " "+ rssFeed);
			if (rssFeed != null) {
				Log.e("RSS URL",
						rssFeed.getTitle() + "" + rssFeed.getLink() + ""
								+ rssFeed.getDescription() + ""
								+ rssFeed.getLanguage());
				RSSDatabaseHandler rssDb = new RSSDatabaseHandler(
						getApplicationContext());
				WebSite site = new WebSite(rssFeed.getTitle(), rssFeed.getLink(), rssFeed.getRSSLink(),
						rssFeed.getDescription());
				rssDb.addSite(site);
				Intent i = getIntent();
				// send result code 100 to notify about product update
				setResult(100, i);
				finish();
			} else {
				// updating UI from Background Thread
				runOnUiThread(new Runnable() {
					public void run() {
						lblMessage.setText("Rss url not found. Please check the url or try again");
					}
				});
			}
			return null;
		}

		/**
		 * After completing background task Dismiss the progress dialog
		 * **/
		protected void onPostExecute(String args) {
			// dismiss the dialog after getting all products
			pDialog.dismiss();
			// updating UI from Background Thread
			runOnUiThread(new Runnable() {
				public void run() {
					if (rssFeed != null) {

					}

				}
			});

		}

	}
}

rss parser add new website

9. Displaying RSS feed articles in listview

We have another screen where list of articles will be displayed in listview once user selects a particular website.

Create xml file called rss_item_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff">
    
    <!-- Header -->
    <include layout="@layout/header"/>
 
    <ListView
        android:id="@android:id/list"
        android:layout_below="@id/layoutHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#bababa"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" 
        android:background="#ffffff" 
        android:cacheColorHint="#00000000"/>
 
</RelativeLayout>

For single list item row – rss_item_list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dip" >
    
    <TextView android:id="@+id/page_url"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"/>
 
    <!-- Article title -->
    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="1dip"
        android:textSize="18dip"
        android:textStyle="bold"
        android:textColor="#303030" />
    
    <!-- published date -->
    <TextView 
        android:id="@+id/pub_date"
        android:layout_below="@id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="3dip"
        android:textSize="14dip"
        android:textColor="#b70400"/>
 
    <!-- article description -->
    <TextView android:id="@+id/link"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingBottom="6dip"
        android:textSize="15dip"
        android:textColor="#8d8d8d"
        android:layout_below="@id/pub_date"/>
</RelativeLayout>

Create a new activity file called ListRSSItemsActivity.java and type the following code. In the following code

-> Site rss link will be received from previous activity.
-> a new background thread which fetches the rss from rss link and parse it
-> Once rss parsing is done, all the articles are displayed in listview

ListRSSItemsActivity.java

package com.androidhive.rssreader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ListRSSItemsActivity extends ListActivity {
	
	// Progress Dialog
	private ProgressDialog pDialog;

	// Array list for list view
	ArrayList<HashMap<String, String>> rssItemList = new ArrayList<HashMap<String,String>>();

	RSSParser rssParser = new RSSParser();
	
	List<RSSItem> rssItems = new ArrayList<RSSItem>();

	RSSFeed rssFeed;
	
	private static String TAG_TITLE = "title";
	private static String TAG_LINK = "link";
	private static String TAG_DESRIPTION = "description";
	private static String TAG_PUB_DATE = "pubDate";
	private static String TAG_GUID = "guid"; // not used
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rss_item_list);
		
		// get intent data
		Intent i = getIntent();
		
		// SQLite Row id
		Integer site_id = Integer.parseInt(i.getStringExtra("id"));
		
		// Getting Single website from SQLite
		RSSDatabaseHandler rssDB = new RSSDatabaseHandler(getApplicationContext());
		
		
		WebSite site = rssDB.getSite(site_id);
		String rss_link = site.getRSSLink();
		
		/**
		 * Calling a backgroung thread will loads recent articles of a website
		 * @param rss url of website
		 * */
		new loadRSSFeedItems().execute(rss_link);
		
		// selecting single ListView item
        ListView lv = getListView();
 
        // Launching new screen on Selecting Single ListItem
        lv.setOnItemClickListener(new OnItemClickListener() {
 
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent in = new Intent(getApplicationContext(), DisPlayWebPageActivity.class);
                
                // getting page url
                String page_url = ((TextView) view.findViewById(R.id.page_url)).getText().toString();
                Toast.makeText(getApplicationContext(), page_url, Toast.LENGTH_SHORT).show();
                in.putExtra("page_url", page_url);
                startActivity(in);
            }
        });
	}
	
	/**
	 * Background Async Task to get RSS Feed Items data from URL
	 * */
	class loadRSSFeedItems extends AsyncTask<String, String, String> {

		/**
		 * Before starting background thread Show Progress Dialog
		 * */
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(
					ListRSSItemsActivity.this);
			pDialog.setMessage("Loading recent articles...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();
		}

		/**
		 * getting all recent articles and showing them in listview
		 * */
		@Override
		protected String doInBackground(String... args) {
			// rss link url
			String rss_url = args[0];
			
			// list of rss items
			rssItems = rssParser.getRSSFeedItems(rss_url);
			
			// looping through each item
			for(RSSItem item : rssItems){
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				
				// adding each child node to HashMap key => value
				map.put(TAG_TITLE, item.getTitle());
				map.put(TAG_LINK, item.getLink());
				map.put(TAG_PUB_DATE, item.getPubdate());
				String description = item.getDescription();
				// taking only 200 chars from description
				if(description.length() > 100){
					description = description.substring(0, 97) + "..";
				}
				map.put(TAG_DESRIPTION, description);

				// adding HashList to ArrayList
				rssItemList.add(map);
			}
			
			// updating UI from Background Thread
			runOnUiThread(new Runnable() {
				public void run() {
					/**
					 * Updating parsed items into listview
					 * */
					ListAdapter adapter = new SimpleAdapter(
							ListRSSItemsActivity.this,
							rssItemList, R.layout.rss_item_list_row,
							new String[] { TAG_LINK, TAG_TITLE, TAG_PUB_DATE, TAG_DESRIPTION },
							new int[] { R.id.page_url, R.id.title, R.id.pub_date, R.id.link });
					
					// updating listview
					setListAdapter(adapter);
				}
			});
			return null;
		}

		/**
		 * After completing background task Dismiss the progress dialog
		 * **/
		protected void onPostExecute(String args) {
			// dismiss the dialog after getting all products
			pDialog.dismiss();
		}
	}
}

rss list rss feed

10. Displaying single article (WebView)

The final step is to display single article in webview. So create a new xml layout for webview

Create a new xml file called webview.xml and type the following code.

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webpage"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

And create a activity class file called DisPlayWebPageActivity.java and type the following code. In the following code

-> Webpage url is received from previous activity
-> After the url is displayed using a webview

DisPlayWebPageActivity.java

package com.androidhive.rssreader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class DisPlayWebPageActivity extends Activity {
	
	WebView webview;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		
		Intent in = getIntent();
		String page_url = in.getStringExtra("page_url");
		
		webview = (WebView) findViewById(R.id.webpage);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.loadUrl(page_url);
		
		webview.setWebViewClient(new DisPlayWebPageActivityClient());
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
	    	webview.goBack();
	        return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}
	
	private class DisPlayWebPageActivityClient extends WebViewClient {
	    @Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        view.loadUrl(url);
	        return true;
	    }
	}

}
rss parser displaying website

11. Deleting Website from SQLite (Long press on Listview to see Context menu)

To delete a website from sqlite database long press on listview to see the context menu with delete option. If you select the delete option that website will be deleted from database.

In your main activity class(AndroidRSSReaderApplicationActivity.java) check for following methods which will create a context menu and perform delete operation on selecting the menu.

public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {} // will create context menu for listview

@Override
    public boolean onContextItemSelected(MenuItem item) {} // will respond to menu selection

android rss parser deleting website
This image is for thumbnail purpose
android rss reader application
Subscribe
Notify of
guest
69 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] this part we completed building required classes for our application. In Android RSS Reader Application using SQLite Part 2 we can start with coding the application layouts and functioning. This image is for thumbnail […]

trackback

[…] Original post: Android RSS Reader Application using SQLite Part 2 […]

Negin
Negin
5 years ago

Hi, i received these errors:

Error:(182, 31) error: unreported exception URISyntaxException; must be caught or declared to be thrown

Error:(184, 59) error: unreported exception HttpException; must be caught or declared to be thrown

Error:Execution failed for task ‘:app:compileDebugJavaWithJavac’.

> Compilation failed; see the compiler error output for details.

what’s wrong?

Negin
Negin
5 years ago

I have another question,

i ran this project but when i wrote url, i received this textview: Rss url not found. Please check the url or try again

i copied rss link and pasted, but didn’t work
and i copied site link to find rss link but didn’t work again.
what should i do?

shareef
shareef
4 years ago

Greate work , why didnt you store the feed items in sql lite too for off line use ?

Peppi
Peppi
4 years ago

nice article compliments!!!Can you tell me how import the new library in Android Studio 1.3.1?

Tarun Gupta
Tarun Gupta
4 years ago

Sir, can you please help me how can i fetch images of any link with this example?

Tarun Gupta
Tarun Gupta
4 years ago

Sir, i want to fetch image, title and description all… can you give me a code for this?

f8
f8
4 years ago

Project is crap..It wont show up any other RSS of other websites apart this one..what a waste of time

Mayur Waghmare
Mayur Waghmare
3 years ago

Sir please share me a news feed application which fetches news through an API

zino
zino
3 years ago

nice

Ha Trien
8 years ago

Good article ! Thanks !

Zulnemeh
Zulnemeh
8 years ago

Thank you very much!

Gaurav
Gaurav
8 years ago

Thanks ravi..
This is Exelent post…can u provide android Runtime Layout samples.
I m new to android…

chirag patel
chirag patel
8 years ago

Ravi Bhai,,How to Open excel file in android..for example how to open excel file without msoffice in adroid

Sergevanlancker
Sergevanlancker
8 years ago

Ravi laisse moi te dire que tu es génial, cela fait plusieurs tutoriel que je suis tu m’as apprit énormément de chose sur le développement dans Android

Ravi Tamada
8 years ago

Je vous remercie et vous êtes les bienvenus

Pratama Nur Wijaya
8 years ago

i will try these one..

samadhaan
samadhaan
8 years ago

hey ravi its a best example thanks and i use your code but when i add a website its show dialog box fetching rss information but after that activity stoped i debug the project and i found that in add new activity the doin background method cant working plz solve my problem

Kaushik
Kaushik
8 years ago
Reply to  samadhaan

Same problem here..

JR
JR
8 years ago

Hi Ravi, I would like first to thank you for your incredible work. It has helped me a lot. Currently I’m working on a project where I need to transmit audio and video streamings between devices. The truth is that I have no idea where to start, if you could help me by posting any related topic it would serve me much. Thanks and GBU

Sunil Chavan
Sunil Chavan
8 years ago

How can i save xml file in drawable folder?

Paolo
Paolo
8 years ago

Hi ravi, are you thinking for a tutorial about fragment ?

Han
Han
8 years ago

Hi Ravi,

Great Post! I would like to know is it possible to sync with google rss reader? Because normally people already setup rss feed with google account so that after login at Android App, allow user to sync from their google account rss reader. Is it possible to do? If you have any ideas, please share! Thanks you so much!

Sabiha1411
Sabiha1411
8 years ago

Nice Article. Helpful 😀

Walaa Mahmoud
Walaa Mahmoud
8 years ago

Hello Ravi , I have to say your blog is fantastic i have learned so much here .Really thanks :))

I’m working on Rss News Reader app and wanted to give user ability to Bookmark any article for checking again , can you help me plz ?

Ravi Tamada
8 years ago
Reply to  Walaa Mahmoud

Just place a button somewhere in app. Add a new table called book marks in SQLIte helper class and implement same method like store bookmark, delete, get all bookmarks etc. Once user presses bookmark button store the url in sqlite database.

Dabears900
Dabears900
8 years ago

This is great, I’ve been looking for a Good Android Rss tutorial and this was it! Thanks! I clicked on an ad too just to say ty, haha

TrongLinh
TrongLinh
8 years ago

Hi Ravi ! I’m error: “could not find method org.jsoup.connect”. While I have add jsoup.jar . please help me !!!

SUN
SUN
8 years ago

wow!

It’s amazing…..you do me a favor!

Amit Suri
Amit Suri
8 years ago

Dear Ravi Sir, Good Morning
In a general way what is the reason of UNFORTUNATELY APPNAME HAS STOPPED, for our knowledge those are making android programs.
Thanks in advance.

Amit Suri
Amit Suri
8 years ago

Dear Ravi Sir, getting Unfortunately AndroidRSSReaderApplication has stopped, why?

Roberto Trejo
Roberto Trejo
7 years ago
Reply to  Amit Suri

Hi, do you debug your app?? When your app is down?

maulik
maulik
7 years ago
Reply to  Roberto Trejo

in android 4.2, logcat says “error occured while executing doinBackground, AsyncTask error i think.. trying to figure the error.. help if u already know

kk
kk
8 years ago

application has stopped …sir what is problem ?

Zombie_nook
Zombie_nook
8 years ago

i can’t to insert rss feed “”” help me to your project

Sur
Sur
7 years ago

Can you please post some tutorial on how to parse xml which have html tags

Manikandan
7 years ago

hai ravi ,Generally ur website is very useful for android developers ,In this RSS FEED APPS ,i have a problem ,first its easily install in eclipse and run the apps ,apps is running i give the url and when the process of fetching it going to error ,i check the coding fully there have no error ,pls help me for this problem…,

pls send some useful sample apps and android study material to my id

Roberto Trejo
Roberto Trejo
7 years ago

Ravi i love your blog, i don’t speak very well inglish, but i hope that you understand me, my app work great, but in the second ListView don’t show me the description only shoe me “<", any problem whit my code?

Roberto Trejo
Roberto Trejo
7 years ago
Reply to  Roberto Trejo

i have a cuestion, i add http://androidhive.info and the description is show, this app is for a specific version of RSS???

Ankit Sonti
Ankit Sonti
7 years ago

hello sir thanks

krunal
krunal
7 years ago

thank you very much, such a great help…, work superb…

viewer
viewer
6 years ago
Reply to  krunal

how did you make work well, that impossible cause its library is occuring ” java.lang.NoClassDefFoundError: org.jsoup.Jsoup “.

John
John
7 years ago

I’m getting a Force Close after i enter the url and click Submit…From LogCat i get java.lang.NoClassDefFoundError: org.jsoup.Jsoup

SudoRoot
SudoRoot
7 years ago

hi everybody!

I’m using this source code.But I have a trouble when running it on Virtual Device,and the errors such as:”the application AndroidRssApplication(process com.androidhive.rssreader) has stopped unexpectedly,please try again”.help me to solve this errors,please!

P/s:I’m beginner on programming android apps

grandslam700
grandslam700
7 years ago

is there a way to preload certain feeds for when the app is first installed, (and keep the add) thing?Just wondering??????

Rabia Athar
Rabia Athar
5 years ago
Reply to  grandslam700

have you got any answer to this?

Rondo
Rondo
6 years ago

Hi Ravi, this is very good tutorial BUT you are not giving an answer to those with the url problem
i believe it caused by this line of code
org.jsoup.nodes.Document doc = Jsoup.connect(url).get();
You would really help by answering this because i am also facing the same problem

Bla Bla Bla
Bla Bla Bla
6 years ago

Hi Ravi, how can I handle leaked window after the dialog event?

Jerome sahayadarlin
Jerome sahayadarlin
6 years ago

Thank you for your great tutorials! I have one question and that’s how can you already set default rss feeds into the application. For example, I have a couple navigation bars for different news categories such as tech, gaming, sports, etc. Then I’m going to set the rss feeds myself to display to the user. So i have tech feeds in the tech section and sports feed in the sports section but I will be the one as a developer setting the url for these feeds. Please answer me as soon as possible. I’m a 14 year old app developer and i have learned a lot from your tutorials. You can also email me if you want to. Thanks!

george
george
6 years ago

Hi all. I am a novice in developing app and thanks to
Ravi for all good work that is doing . I’m working at a simple app and I get
stuck . if you have knowledge of
building android apps, and make team
with me please replay to george.celsie@gmail.com . Thanks ang
good luck for all

Landon
Landon
6 years ago

There are deffinatly errors in this code i found tons. i am weoking on debugging it now. i may be able to post the fixes once i have it fixed.

Amrendra Kumar
Amrendra Kumar
5 years ago
Reply to  Landon

Hi Landon, Did you fixed the code ?
I tried to execute the code attached and it gives message “unfortunately, androidrssreaderapplication has stoped”

Charles
Charles
6 years ago

please ravi, i imported your code into my eclipse, no error, but after clicking in the “submit” button to add new site it says “unfortunately, androidrssreaderapplication has stoped” and forcefully close it. please help me its very urgent.thanks

Tumuhimbise Samson
Tumuhimbise Samson
6 years ago

Please help i can’t download the source code for this tutorial

natasha
natasha
6 years ago

for the ListRSSItemsActivity i get an error as follows in the log-cat

08-01 15:40:05.687: I/tag(5714): onCreate

08-01 15:40:05.703: D/AbsListView(5714): checkAbsListViewlLogProperty get invalid command

08-01 15:40:05.704: I/tag(5714): intent

08-01 15:40:05.705: D/AndroidRuntime(5714): Shutting down VM

08-01 15:40:05.705: W/dalvikvm(5714): threadid=1: thread exiting with uncaught exception (group=0x4192bc98)

08-01 15:40:05.705: W/dalvikvm(5714): threadid=1: uncaught exception occurred

08-01 15:40:05.705: W/System.err(5714): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rssreader/com.example.rssreader.ListRSSItemsActivity}: java.lang.NumberFormatException: Invalid int: “null”

08-01 15:40:05.706: W/System.err(5714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)

08-01 15:40:05.706: W/System.err(5714): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)

08-01 15:40:05.706: W/System.err(5714): at android.app.ActivityThread.access$800(ActivityThread.java:151)

08-01 15:40:05.706: W/System.err(5714): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)

please let me know what is the reason for the same.

Yazdan
Yazdan
6 years ago

hi , this app does not work . I don t why . I import the code but when I want to add site it stop working.

Sujeeth
Sujeeth
6 years ago

hi,this apps does not work when i m going add the site my apps getting force closed.nd logcat show me a window Leaked Error……..

Moktar Hossain
Moktar Hossain
6 years ago

Ravi Bhai, I download the projects when I click the submit button the app is crash and stop working ……..plz help me

Ravi Tamada
6 years ago
Reply to  Moktar Hossain

Check your logcat for errors.

Neha
Neha
5 years ago
Reply to  Ravi Tamada

Sir this error is coming please help ASAP…….Caused by: java.lang.NoClassDefFoundError: org.jsoup.Jsoup

coder729
coder729
6 years ago
Reply to  Moktar Hossain

hi moktar, I am also getting the same thing, have you fixed the bug…

69
0
Would love your thoughts, please comment.x
()
x