January 25th, 2011, 07:54 PM
|
#1 (permalink)
|
|
ROM Developer
Thread Author (OP)
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
|
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.
|
|
|