MyRssReader2public class MyRssReader2 extends android.app.Activity
Fields Summary |
---|
private ArrayList | mFeeds | android.widget.ListView | mRssList | private Logger | mLogger |
Methods Summary |
---|
private java.util.ArrayList | initializeList()
ArrayList<RssItem> list = new ArrayList<RssItem>();
list.add(new RssItem("http://www.sciam.com/xml/sciam.xml", "Scientific American"));
list.add(new RssItem("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml", "BBC"));
list.add(new RssItem("http://www.theonion.com/content/feeds/daily.", "The Onion"));
list.add(new RssItem("http://feeds.engadget.com/weblogsinc/engadget", "Engadget"));
return list;
| public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
// Load screen layout.
setContentView(R.layout.main_screen2);
// Populate our list
mFeeds = initializeList();
mLogger.info("MyRssReader.onCreate-1 mFeeds value:" + mFeeds.size());
// BEGIN_INCLUDE(2_2)
// Populate ArrayAdapter and bind it to ListView
mRssList = (ListView)findViewById(R.id.rssListView);
if(mRssList == null){
// Note: Calling showAlert() would fail here because dialogs opened
// in onCreate won't be displayed properly, if at all.
mLogger.warning("MyRssReader.onCreate-2 -- Couldn't instantiate a ListView!");
}
RssDataAdapter<RssItem> adap = new RssDataAdapter<RssItem>(this, R.layout.add_item, mFeeds);
if(adap == null){
mLogger.warning("MyRssReader.onCreate-3 -- Couldn't instantiate RssDataAdapter!");
}
if(mFeeds == null){
mLogger.warning("MyRssReader.onCreate-4 -- Couldn't instantiate a ListView!");
}
mRssList.setAdapter(adap);
// END_INCLUDE(2_2)
mLogger.info("MyRssReader.onCreate-5 -- Loading preferences.");
// Set the last selected item.
// (icicle is only set if this is being restarted).
if(savedInstanceState != null && savedInstanceState.containsKey("lastIndexItem"))
{
Integer selectedItem = savedInstanceState.getInteger("lastIndexItem");
if(selectedItem >= 0 && selectedItem < mRssList.getChildCount()){
mRssList.setSelection(savedInstanceState.getInteger("lastIndexItem"));
}
mLogger.info("MyRssReader.onCreate-6 -- Last selected item:" + selectedItem);
}
| public boolean | onCreateOptionsMenu(android.view.Menu menu)
// Always call the superclass implementation to
// provide standard items.
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "Start RSS Service", null);
menu.add(0, 1, "Stop RSS Service", null);
menu.add(0, 2, "Add New Feed", null);
menu.add(0, 3, "Delete Feed", null);
menu.add(0, 4, "Update All Feeds", null);
return true;
| public boolean | onOptionsItemSelected(Menu.Item item)
switch (item.getId()){
case 0:
showAlert(null, "You clicked 'start'!", "ok", null, false, null);
break;
case 1:
showAlert(null, "You clicked stop!", "ok", null, false, null);
break;
case 2:
showAlert(null, "You clicked 'Add'!", "ok", null, false, null);
break;
case 3:
showAlert(null, "You clicked 'Delete'!", "ok", null, false, null);
break;
case 4:
showAlert(null, "You clicked 'Update'!", "ok", null, false, null);
break;
default:
showAlert(null, "I have no idea what you clicked!", "ok", null, false, null);
break;
}
return true;
| public boolean | onPrepareOptionsMenu(android.view.Menu menu)
return true;
| protected void | onSaveInstanceState(android.os.Bundle outState)
int index = mRssList.getSelectedItemIndex();
if(index > -1){
outState.putInteger("lastIndexItem", index);
}
|
|