Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old January 25th, 2011, 07:54 PM   #1 (permalink)
ROM Developer
Thread Author (OP)
 
cr5315's Avatar
 
Join Date: Jul 2010
Location: Narnia
Posts: 435
 
Device(s): Current: HTC Evo 4G, Asus Nexus 7 Retired: LG Ally
Carrier: Not Provided

Thanks: 103
Thanked 161 Times in 105 Posts
Default Changing RSS url from a dialog

I'm making an RSS reader and I'm trying to add a way to change what feed it is viewing. So far I haven't been able to figure out how to change it.

Here's the part at the beginning of onCreate
Code:
private void readRss(){
  
 feedTitle.setText("--- wait ---");
 feedDescribtion.setText("");
 feedPubdate.setText("");
 feedLink.setText("");
 setListAdapter(null);

 Toast.makeText(this, "Reading RSS, Please wait.", Toast.LENGTH_LONG).show();
  
      try {
  URL rssUrl = new URL("http://feeds.feedburner.com/AndroidPhoneFans?format=xml");
  SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
  SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
  XMLReader myXMLReader = mySAXParser.getXMLReader();
  RSSHandler myRSSHandler = new RSSHandler();
  myXMLReader.setContentHandler(myRSSHandler);
  InputSource myInputSource = new InputSource(rssUrl.openStream());
  myXMLReader.parse(myInputSource);
And the code for the dialog, which is brought up through a menu.
Code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
 // TODO Auto-generated method stub
	final AlertDialog.Builder alert = new AlertDialog.Builder(this);
	final EditText input = new EditText(this);
	alert.setTitle("Set RSS URL");
	alert.setMessage("Example: http://www.example.com/rss.xml");
	alert.setView(input);
	alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int whichButton) {
			String value = input.getText().toString().trim();
			Toast.makeText(getApplicationContext(), value,
					Toast.LENGTH_SHORT).show();
			try {
				new URL(value);
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	});

	alert.setNegativeButton("Cancel",
			new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					dialog.cancel();
				}
			});
	alert.show();
I'm pretty sure that what I have is wrong (mostly because it didn't work) but Eclipse isn't giving me any errors.

cr5315 is offline  
Reply With Quote
sponsored links
Old January 26th, 2011, 07:36 AM   #2 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 313
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 53 Times in 51 Posts
Default

How do you want it to change? What do you want to happen? A little more explanation would be appreciated.
miXer is offline  
Reply With Quote
Old January 26th, 2011, 03:55 PM   #3 (permalink)
ROM Developer
Thread Author (OP)
 
cr5315's Avatar
 
Join Date: Jul 2010
Location: Narnia
Posts: 435
 
Device(s): Current: HTC Evo 4G, Asus Nexus 7 Retired: LG Ally
Carrier: Not Provided

Thanks: 103
Thanked 161 Times in 105 Posts
Default

If the user typed in
Code:
http://www.engadget.com/rss.xml
it would change
Code:
URL rssUrl = new URL("http://feeds.feedburner.com/AndroidPhoneFans?format=xml");
into
Code:
URL rssUrl = new URL("http://www.engadget.com/rss.xml");
and have the app load that. (I'm thinking restarting the activity or launching a new one, but that's just me).
cr5315 is offline  
Reply With Quote
Reply
Tags
menu, rss, rss feed, url


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:50 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.