title: Clickable Items From ListView RSS Reader
body: <p>I was following an online mobile tutorial about RSS Readers, and before I could go through the complete tutorial it was removed. I have waited for some time now (it hasn't come back!), and I have tried to complete the code myself. On my own, I have been able to get my app to parse data and display out into a ListView. I need some help making it so that after any item is clicked, it opens up a WebView and displays the content associated to the URL attached to that item. Can someone tell me what I am missing and doing wrong here? I have been doing my best to fill in the blanks, but the items I click from ListView still do nothing.</p>
  
  <p>MainActivity</p>
  
  <pre><code>public class MainActivity extends Activity implements OnItemClickListener {
  
  ListView feedListView;
  List&lt;FeedStructure&gt; rssStr;
  private FeedListAdapter adapter;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      feedListView = (ListView) findViewById(R.id.list);
      feedListView.setVerticalFadingEdgeEnabled(true);
      RssFeedTask rssTask = new RssFeedTask();
      rssTask.execute();
  }
  
  //setup asynctask
  private class RssFeedTask extends AsyncTask&lt;String, Void, String&gt; {
  
      private ProgressDialog Dialog;
      String response = "";
  
      @Override
      protected void onPreExecute() {
          Dialog = new ProgressDialog(MainActivity.this);
          Dialog.setMessage("Loading...");
          Dialog.show();
      }
  
      @Override 
      protected String doInBackground(String... urls) {
          try {
              String feed = "http://feeds.feedburner.com/drxeno/home";
              XMLHandler rh = new XMLHandler();
              rssStr = rh.getLatestArticles(feed);
          } catch (Exception e) {
          }   
          return response;        
      }
  
      @Override
      protected void onPostExecute(String result) {
          if (rssStr != null) {
              adapter = new FeedListAdapter(MainActivity.this, rssStr);
              feedListView.setAdapter(adapter);
          }
          Dialog.dismiss();
      }   
  }
  
  //@Override
  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
  
      ListView lv = (ListView) findViewById(R.id.list);
      adapter = new FeedListAdapter(this, rssStr);
      lv.setAdapter(adapter);
      lv.setOnItemClickListener(this);
  
  
      Intent intent = new Intent(MainActivity.this, WebviewActivity.class);
      new Bundle();
      intent.putExtra("b", rssStr.get(pos).getLink());
  
      //get the selected item and do the further process  
      lv.getItemAtPosition(pos);
      ((FeedStructure) lv.getItemAtPosition(pos)).getLink();
      }   
  }
  </code></pre>
  
  <p>FeedStructure</p>
  
  <pre><code>public class FeedStructure {
  
  private String title;
  private String pubDate;
  private String imgLink;
  private String creator;
  private String link;
  private long item;
  
  //@param item set item
  public void setItem(long item) {
      this.item = item;
  }
  
  //@return item
  public long getItem() {
      return item;
  }
  
  //@param title set title
  public void setTitle(String title) {
      this.title = title;
  }
  
  //@return title
  public String getTitle() {
      return title;
  }
  
  //truncate title
  public String toString() {
      if (title.length() &gt; 10) {
          return title.substring(0, 10) + "...";
      }
      return title;
  }
  
  //@param pubDate set pubDate
  public void setPubDate(String pubDate) {
      this.pubDate = pubDate;
  }
  
  //@return pubDate
  public String getPubDate() {
      return pubDate;
  }
  
  //@param imgLink set imgLink
  public void setImgLink(String imgLink) {
      this.imgLink = imgLink;
  }
  
  //@return imgLink
  public String getImgLink() {
      return imgLink;
  }
  
  //@param creator set creator
  public void setCreator(String creator) {
      this.creator = creator;
  }
  
  //@return creator
  public String getCreator() {
      return creator;
  }   
  
  //@param creator set URL
  public void setLink(String link) {
      this.link = link;
  }
  
  //@return URL
  public String getLink() {
      return link;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Handler</p>
  
  <pre><code>public class XMLHandler extends DefaultHandler {
  
  private FeedStructure feedStr = new FeedStructure();
  private List&lt;FeedStructure&gt; rssList = new ArrayList&lt;FeedStructure&gt;();
  
  private int acticlesAdded = 0;
  
  private static final int ARTICLES_LIMIT = 50;
  StringBuilder chars = new StringBuilder();
  
  public void startElement(String uri, String localName, String qName, Attributes atts) 
          throws SAXException {
  
      // TODO Auto-generated method stub
      super.startElement(uri, localName, qName, atts);
      chars = new StringBuilder();
  }
  
  public void endElement(String uri, String localName, String qName) throws SAXException {
      // TODO Auto-generated method stub
      super.endElement(uri, localName, qName);
  
      if (localName.equalsIgnoreCase("title")) {
          feedStr.setTitle(chars.toString());
      }
      else if (localName.equalsIgnoreCase("pubDate")) {
          feedStr.setPubDate(chars.toString());
      }       
      else if (localName.equalsIgnoreCase("creator")) {
          feedStr.setCreator(chars.toString());
      }
      else if (localName.equalsIgnoreCase("link")) {
          feedStr.setLink(chars.toString());
      }
      if (localName.equalsIgnoreCase("item")) {
          rssList.add(feedStr);
  
          feedStr = new FeedStructure();
          acticlesAdded++;
          if (acticlesAdded &gt;= ARTICLES_LIMIT) {
              throw new SAXException();
          }
      }
  }
  
  public void characters(char ch[], int start, int length) {
      chars.append(new String(ch, start, length));
  }
  
  public List&lt;FeedStructure&gt; getLatestArticles(String feedUrl) {
      URL url = null;
      try {
          SAXParserFactory spf = SAXParserFactory.newInstance();
          SAXParser sp = spf.newSAXParser();
          XMLReader xr = sp.getXMLReader();
          url = new URL(feedUrl);
          xr.setContentHandler(this);
          xr.parse(new InputSource(url.openStream()));
      } catch (IOException e) { Log.d(TAG, "IOException");
      } catch (SAXException e) { Log.d(TAG, "SAXException");
      } catch (ParserConfigurationException e) { 
      }   
      return rssList; 
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Adapter</p>
  
  <pre><code>public class FeedListAdapter extends ArrayAdapter&lt;FeedStructure&gt; {
  
  List&lt;FeedStructure&gt; metaData = null;
  public FeedListAdapter(Activity activity, List&lt;FeedStructure&gt; metaDataParse) {
      super(activity, 0, metaDataParse);
      metaData = metaDataParse;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      Activity activity = (Activity) getContext();
      LayoutInflater inflater = activity.getLayoutInflater();
  
      View rowView = inflater.inflate(R.layout.activity_main_format, null);
      TextView titleTextView = (TextView) rowView.findViewById(R.id.title_format);
      TextView creatorTextView = (TextView) rowView.findViewById(R.id.creator_format);
      TextView dateTextView = (TextView) rowView.findViewById(R.id.date_format);
      ImageView imageView = (ImageView) rowView.findViewById(R.id.image_format);
          try {
              titleTextView.setText(metaData.get(position).getTitle());
              creatorTextView.setText("Creator: " + metaData.get(position).getCreator());
  
              //reformat current date into another format
              if (metaData.get(position).getPubDate() != null) {
                  String pubDate = metaData.get(position).getPubDate();
  
                  SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy", Locale.ENGLISH);
  
                  try {
                      Date pDate = df.parse(pubDate);
                      dateTextView.setText("Published: " + df.format(pDate));
                  } catch (ParseException e) {
  
                  }
              }
  
              //pull in ImgLink, if there is no image use static image
              if (metaData.get(position).getImgLink() != null) {
                  URL feedImage = new URL (metaData.get(position).getImgLink().toString());
                                      if (!feedImage.toString().equalsIgnoreCase("null")) {
                      HttpURLConnection conn = (HttpURLConnection)feedImage.openConnection();
                      InputStream is = conn.getInputStream();
                      Bitmap img = BitmapFactory.decodeStream(is);
                      imageView.setImageBitmap(img);
                  } else {
                      imageView.setBackgroundResource(R.drawable.img2);
                  }
              }
  
          } catch (MalformedURLException e) { 
          } catch (IOException e) { 
          }
          return rowView;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>WebView Activity</p>
  
  <pre><code>public class WebviewActivity extends Activity {
  private WebView webview;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.webview);
  
      this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
      getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);  
  
      Bundle b = getIntent().getExtras();
      String KEY_LINK = b.getString("link");
  
      WebView myWebView = (WebView) findViewById(R.id.webview);
      WebSettings webSettings = myWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
  
      webview.setWebViewClient(new MyWebViewClient(this));
      webview.getSettings().setAppCacheEnabled(false);
      webview.getSettings().setBuiltInZoomControls(true); 
  
      webview.getSettings().setDisplayZoomControls(true); 
      webview.getSettings().setAllowContentAccess(true); 
      webview.getSettings().setSupportZoom(true);
  
      webview.setInitialScale(1);
      webview.loadUrl(KEY_LINK);
  
      final Activity MyActivity = this;
  
      myWebView.setWebChromeClient(new WebChromeClient() {
          public void onProgressChanged(WebView view, int progress)
          {
              MyActivity.setTitle("Loading test...");
              MyActivity.setProgress(progress * 100); 
              if (progress == 100) {
                  MyActivity.setTitle(R.string.app_name);
              }   
          }
      });
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>WebViewClient</p>
  
  <pre><code>public class MyWebViewClient extends WebViewClient {
  
  public MyWebViewClient(WebviewActivity webviewActivity) {
      // TODO Auto-generated constructor stub
  }
  
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      if (Uri.parse(url).getHost().equals("www.ljtatum.blog.com")) {
  
          return false;
      }
  
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have been trying to fill in the blanks for weeks, and I contacted the author several times. Hopefully you can help me out, thanks!</p>