I know I’m over looking this or over thinking this but I can not seem to figure out how to launch the link of an rss feed when the user clicks it. I’m using a DOM Parser to parse the xml file into a listview and get all the info from the xml file. The problem I’m having is parsing it into a Custom WebActivity that i have that should load a webview client that i have as well. Here is the code i’m working with.
Main Activity
public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://treymorgan.net/feed";
// XML node keys
static final String KEY_ITEM = "item"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_PUB_DATE = "pubDate";
static final String KEY_LINK = "guid";
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_PUB_DATE, parser.getValue(e, KEY_PUB_DATE));
map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
// adding HashList to ArrayList
songsList.add(map);
}
list=(ListView)findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
EDIT : This is the section of code i’m haveing trouble with … the onItemClick method to send the url from the rss feed to the webview activity so that it can be viewed in app and not through the native browser on the device
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(CustomizedListView.this, WebviewActivity.class);
Bundle b = new Bundle();
intent.putExtra("KEY_LINK", b);
startActivity(intent);
}
});
}
}
here is my Webview activity
public class WebviewActivity extends Activity{
private WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
Bundle b = getIntent().getExtras();
String KEY_LINK = b.getString("KEY_LINK");
webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new MyWebViewClient(this));
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setBuiltInZoomControls(true);
webview.setInitialScale(1);
webview.loadUrl(KEY_LINK);
}
}
So basicly, what I’m wanting to do is String the KEY_GUID to the WebviewActivity and I can’t seem to figure out how to recive the string from one activity to the other. Thanks in advance for any help
EDIT: OK I’ve worked on this a while and I have updated the code i’m using that is relevent to this issue. Now I have no errors and when i click an item it will open the WebviewActivity but it does not load the website nor does it attach my webview client to it either. Can anyone help me figure this out?
EDIT:
when i load the code like this:
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(CustomizedListView.this, WebviewActivity.class);
Bundle b = new Bundle();
intent.putExtra("b", "http://www.google.com" );
startActivity(intent);
It opens the webview activity and loads google up just fine. So maybe the problem i am having now is how to get the link that i need from my DOM parser. Anyone have any ideas?
Ok here is the answer to my question i asked. This worked great for me and did exactly as i wanted. Here is the working code for it