Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid RSS Modifying a URL link and Passing it to another Activity
    primarykey
    data
    text
    <p>I have an RSS program that implements a DOMParser and one of the Nodes is a link to another website. In the program I am passing this string to another activity where the person can click and go to the website. My question is after I parse the Node/link: </p> <p>How can I change the first original address but keep the backend: <a href="http://www.THEIRwebsite.com/php&amp;blah&amp;31&amp;blahblah&amp;blah432&amp;blah" rel="nofollow noreferrer">http://www.THEIRwebsite.com/php&amp;blah&amp;31&amp;blahblah&amp;blah432&amp;blah</a> </p> <p>to:</p> <p><a href="http://www.MYwebsite.com/php&amp;blah&amp;31&amp;blahblah&amp;blah432&amp;blah" rel="nofollow noreferrer">http://www.MYwebsite.com/php&amp;blah&amp;31&amp;blahblah&amp;blah432&amp;blah</a> </p> <p>And pass that to my next activity? I can provide my code if needed.</p> <p>EDIT - Yes I have permission, I work with the site. I know how to pass the link to the next Activity. The app has a gridview with images and then the user clicks on an image and that takes them to a Fragment with a full image and description where there is a button with OnClickListener that loads a WebView(the link). I just do not know how to modify the first www.THEIRWebsite.com so it passes my website but keeps the trailing part(I don't know technical name of that...sorry). </p> <p>LAST EDIT! Sorry...Here is the DetailFragment and WebActivity (Probably shouldn't of posted the ListActivity...this is where the "link" is passed to Thanks!</p> <p>Solution - This is the answer...Sorry for wasting everyone time. <a href="https://stackoverflow.com/questions/5754363/android-how-to-replace-part-of-a-string-by-another-string">Android - how to replace part of a string by another string?</a></p> <p>public class DOMParser {</p> <pre><code>private RSSFeed _feed = new RSSFeed(); public RSSFeed parseXml(String xml) { URL url = null; try { url = new URL(xml); } catch (MalformedURLException e1) { e1.printStackTrace(); } try { // Create required instances DocumentBuilderFactory dbf; dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // Parse the xml Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); // Get all tags. NodeList nl = doc.getElementsByTagName("item"); int length = nl.getLength(); for (int i = 0; i &lt; length; i++) { Node currentNode = nl.item(i); RSSItem _item = new RSSItem(); NodeList nchild = currentNode.getChildNodes(); int clength = nchild.getLength(); // Get the required elements from each Item for (int j = 1; j &lt; clength; j = j + 2) { Node thisNode = nchild.item(j); String theString = null; String nodeName = thisNode.getNodeName(); theString = nchild.item(j).getFirstChild().getNodeValue(); if (theString != null) { if ("title".equals(nodeName)) { // Node name is equals to 'title' so set the Node // value to the Title in the RSSItem. _item.setTitle(theString); } else if ("description".equals(nodeName)) { _item.setDescription(theString); } else if ("wc:image_url".equals(nodeName)) { _item.setImage(theString); } else if ("wc:link".equals(nodeName)) { //Here is where I want to take this link and modify //the first part _item.setLink(theString); } } } // add item to the list _feed.addItem(_item); } } catch (Exception e) { } return _feed; } </code></pre> <p>}</p> <p>ListActivity { ... public View getView(int position, View convertView, ViewGroup parent) {</p> <pre><code> // Inflate the item layout and set the views View listItem = convertView; int pos = position; if (listItem == null) { listItem = layoutInflater.inflate(R.layout.grid_item, null); } // Initialize the views in the layout ImageView iv = (ImageView) listItem.findViewById(R.id.thumb); TextView tvTitle = (TextView) listItem.findViewById(R.id.title); // Set the views in the layout imageLoader.DisplayImage(feed.getItem(pos).getLargeImage(), iv); tvTitle.setText(feed.getItem(pos).getTitle()); </code></pre> <p><code>enter code here</code>public class DetailFragment extends Fragment { private int fPos; RSSFeed fFeed;</p> <pre><code>Button button1; private ImageLoader imageLoader; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); fFeed = (RSSFeed) getArguments().getSerializable("feed"); fPos = getArguments().getInt("pos"); imageLoader = new ImageLoader(getActivity().getApplicationContext()); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); fFeed = (RSSFeed) getArguments().getSerializable("feed"); fPos = getArguments().getInt("pos"); imageLoader = new ImageLoader(getActivity().getApplicationContext()); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent mainIntent = new Intent(getActivity(), WebActivity.class); Bundle bundle = new Bundle(); bundle.putSerializable("feed", fFeed); mainIntent.putExtra("wc:link", fFeed.getItem(fPos).getLink()); mainIntent.putExtras(bundle); mainIntent.putExtra("pos", fPos); startActivity(mainIntent); } }); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater .inflate(R.layout.detail_fragment, container, false); button1 = (Button) view.findViewById(R.id.button1); // Initializr views TextView title = (TextView) view.findViewById(R.id.title); TextView description = (TextView) view.findViewById(R.id.description); ImageView iv = (ImageView) view.findViewById(R.id.thumb); // Enable the vertical fading edge (by default it is disabled) ScrollView sv = (ScrollView) view.findViewById(R.id.sv); sv.setVerticalFadingEdgeEnabled(true); // Set the views title.setText(fFeed.getItem(fPos).getTitle()); description.setText(fFeed.getItem(fPos).getDescription()); imageLoader.DisplayImage(fFeed.getItem(fPos).getLargeImage(), iv); return view; } } </code></pre> <p>WebActivity public class WebActivity extends Activity {</p> <pre><code>WebView wv; int fPos; RSSFeed fFeed; String _link; String ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"; /* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO Auto-generated method stub setContentView(R.layout.webpage); fFeed = (RSSFeed) getIntent().getExtras().get("feed"); fPos = getIntent().getExtras().getInt("pos"); Intent in = getIntent(); String _link = in.getStringExtra("wc:link"); WebView wv = (WebView) findViewById(R.id.webView1); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setPluginState(PluginState.ON); wv.getSettings().setPluginsEnabled(true); wv.getSettings().setAllowFileAccess(true); wv.getSettings().setLoadsImagesAutomatically(true); wv.getSettings().setBuiltInZoomControls(true); wv.getSettings().setUserAgentString(ua); wv.getSettings().setJavaScriptEnabled(true); wv.setWebChromeClient(new WebChromeClient()); wv.loadUrl(_link); } public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPause() { if (wv != null) { wv.onPause(); } super.onPause(); } @Override public void onResume() { super.onResume(); if (wv != null) { wv.onResume(); } } public void updateUrl(String newUrl) { if (wv != null) { wv.loadUrl(newUrl); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload