Quantcast
Channel: Android RSS Feeds now displaying blank - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Android RSS Feeds now displaying blank

$
0
0

I have previsously parsed this RSS Feed, now that I have updated it to use a AsyncTask it now displays a blank screen instead of a filled listviewCODE:

public class CustomizedListView extends Activity {static String URL= "http://scout.org/rss/feed/all";static final String KEY_ITEM = "item"; static final String KEY_TITLE = "title";static final String KEY_DESCRIPTION = "description";static final String KEY_LINK = "link";static final String KEY_PUB_DATE = "pubDate"; String PATH = Environment.getExternalStorageDirectory()+"/SCOUTS/";ListView list;LazyAdapter adapter;@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.news);    SharedPreferences sharedPrefs =   PreferenceManager.getDefaultSharedPreferences(this);    URL= sharedPrefs.getString("news_feed", "-1");    ArrayList<HashMap<String, String>> libraryList = new ArrayList<HashMap<String, String>>();    list=(ListView)findViewById(R.id.listView1);                adapter=new LazyAdapter(CustomizedListView.this, libraryList);            list.setAdapter(adapter);     new MyAsyncTask() .execute();}  class MyAsyncTask extends AsyncTask<String, Integer, ArrayList<HashMap<String, String>> > {      private ProgressDialog progressDialog = new ProgressDialog(CustomizedListView.this);        protected void onPreExecute() {           progressDialog.setMessage("Loading Latest WOSM News");           progressDialog.show();}        ArrayList<HashMap<String, String>> libraryList = new ArrayList<HashMap<String, String>>();              @Override          protected ArrayList<HashMap<String, String>> doInBackground(String... params) {                  try {                    new DefaultHttpClient().execute(new HttpGet(URL))                    .getEntity().writeTo(                            new FileOutputStream(new File(PATH,"news.xml")));                } catch (ClientProtocolException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (FileNotFoundException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (IOException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }                  File dir = Environment.getExternalStorageDirectory();                  File yourFile = new File(dir, "/SCOUTS/news.xml");                  FileInputStream stream = null;                try {                    stream = new FileInputStream(yourFile);                } catch (FileNotFoundException e2) {                    // TODO Auto-generated catch block                    e2.printStackTrace();                }                  String jString = null;                  try {                      FileChannel fc = stream.getChannel();                      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());                      /* Instead of using default, pass in a decoder. */                      jString = Charset.defaultCharset().decode(bb).toString();                    } catch (IOException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }                    finally {                      try {                        stream.close();                    } catch (IOException e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                    }                final ArrayList<HashMap<String, String>> libraryList = new ArrayList<HashMap<String, String>>();                XMLParser parser = new XMLParser();                String xml = jString;                Document doc = parser.getDomElement(xml);                 NodeList nl = doc.getElementsByTagName(KEY_ITEM);                for (int i = 0; i < nl.getLength(); i++) {                    HashMap<String, String> map = new HashMap<String, String>();                    Element e = (Element) nl.item(i);                    map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));                    map.put(KEY_DESCRIPTION, parser.getValue(e, KEY_DESCRIPTION));                    map.put(KEY_LINK, parser.getValue(e, KEY_LINK));                    map.put(KEY_PUB_DATE, parser.getValue(e, KEY_PUB_DATE));                    libraryList.add(map);            }            return libraryList;}          @Override          protected void onPostExecute(ArrayList<HashMap<String, String>> result) {                list=(ListView)findViewById(R.id.listView1);                            adapter=new LazyAdapter(CustomizedListView.this, libraryList);                        list.setAdapter(adapter);                this.progressDialog.dismiss();                list.setOnItemClickListener(new OnItemClickListener() {                    public void onItemClick(AdapterView<?> parent, View view,                            int position, long id) {                          HashMap<String, String> map = libraryList.get(position);                        Intent in = new Intent(CustomizedListView.this, org.scouts.android.news.Podcast.class);                        in.putExtra(KEY_TITLE, map.get(KEY_TITLE));                        in.putExtra(KEY_DESCRIPTION, map.get(KEY_DESCRIPTION));                        in.putExtra(KEY_LINK, map.get(KEY_LINK));                        in.putExtra(KEY_PUB_DATE, map.get(KEY_PUB_DATE));                        startActivity(in);                    }                });         ;}}}

I do not know what is causing it but if you can help, please do


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images