1. Hot New Devices! HTC One M9 | Samsung Galaxy S6 | LG G4

Changing RSS url from a dialog


  1. cr5315

    cr5315 Well-Known Member Developer

    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 (Text):
    1. private void readRss(){
    2.  
    3.  feedTitle.setText("--- wait ---");
    4.  feedDescribtion.setText("");
    5.  feedPubdate.setText("");
    6.  feedLink.setText("");
    7.  setListAdapter(null);
    8.  
    9.  Toast.makeText(this, "Reading RSS, Please wait.", Toast.LENGTH_LONG).show();
    10.  
    11.       try {
    12.   URL rssUrl = new URL("http://feeds.feedburner.com/AndroidPhoneFans?format=xml");
    13.   SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
    14.   SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
    15.   XMLReader myXMLReader = mySAXParser.getXMLReader();
    16.   RSSHandler myRSSHandler = new RSSHandler();
    17.   myXMLReader.setContentHandler(myRSSHandler);
    18.   InputSource myInputSource = new InputSource(rssUrl.openStream());
    19.   myXMLReader.parse(myInputSource);
    And the code for the dialog, which is brought up through a menu.
    Code (Text):
    1. @Override
    2. public boolean onOptionsItemSelected(MenuItem item) {
    3.  // TODO Auto-generated method stub
    4.     final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    5.     final EditText input = new EditText(this);
    6.     alert.setTitle("Set RSS URL");
    7.     alert.setMessage("Example: http://www.example.com/rss.xml");
    8.     alert.setView(input);
    9.     alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    10.         public void onClick(DialogInterface dialog, int whichButton) {
    11.             String value = input.getText().toString().trim();
    12.             Toast.makeText(getApplicationContext(), value,
    13.                     Toast.LENGTH_SHORT).show();
    14.             try {
    15.                 new URL(value);
    16.             } catch (MalformedURLException e) {
    17.                 // TODO Auto-generated catch block
    18.                 e.printStackTrace();
    19.             }
    20.            
    21.         }
    22.     });
    23.  
    24.     alert.setNegativeButton("Cancel",
    25.             new DialogInterface.OnClickListener() {
    26.                 public void onClick(DialogInterface dialog, int whichButton) {
    27.                     dialog.cancel();
    28.                 }
    29.             });
    30.     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.

    Advertisement
  2. miXer

    miXer Well-Known Member

    How do you want it to change? What do you want to happen? A little more explanation would be appreciated.
  3. cr5315

    cr5315 Well-Known Member Developer

    If the user typed in
    Code (Text):
    1. http://www.engadget.com/rss.xml
    it would change
    Code (Text):
    1. URL rssUrl = new URL("http://feeds.feedburner.com/AndroidPhoneFans?format=xml");
    into
    Code (Text):
    1. 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).

Share This Page