• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Changing RSS url from a dialog

cr5315

Android Enthusiast
Jul 23, 2010
434
158
Narnia
cr5315.com
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.
 
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).
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones