Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OnTvRss extends LinearLayout implements OnItemClickListener{
- // XMLParser parser;
- static ArrayList<String> headlines, des, date, links, images;
- static String GerUlr = null;
- SpecialAdapter adapter;
- static ListView list;
- String TAG = OnTvRss.class.getSimpleName();
- public static AssetManager manager;
- static Context con;
- LayoutInflater mInflater;
- String onTVurl = "http://feeds.feedburner.com/ontveg";
- public OnTvRss(Context context, AttributeSet attr) {
- super(context, attr);
- OnTvRss.con = context;
- OnTvRss.list = new ListView(getContext());
- new walaa().execute(onTVurl);
- OnTvRss.list.setOnItemClickListener( OnTvRss.this);
- }
- public OnTvRss(Context context) {
- super(context);
- OnTvRss.con = context;
- OnTvRss.list = new ListView(getContext());
- mInflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- new walaa().execute(onTVurl);
- OnTvRss.list.setOnItemClickListener(OnTvRss.this);
- }
- public InputStream getInputStream(URL url) {
- try {
- return url.openConnection().getInputStream();
- } catch (IOException e) {
- return null;
- }
- }
- private class walaa extends AsyncTask<String, Void, ArrayList<String>> {
- @Override
- protected ArrayList<String> doInBackground(String... status) {
- OnTvRss.this.addView(OnTvRss.list);
- headlines = new ArrayList<String>();
- des = new ArrayList<String>();
- date = new ArrayList<String>();
- links = new ArrayList<String>();
- images = new ArrayList<String>();
- try {
- URL url = new URL(status[0]);
- XmlPullParserFactory factory = XmlPullParserFactory
- .newInstance();
- factory.setNamespaceAware(false);
- XmlPullParser xpp = factory.newPullParser();
- // We will get the XML from an input stream
- xpp.setInput(getInputStream(url), "UTF_8");
- /*
- * We will parse the XML content looking for the tag. 16
- * However, the rss feed name also is enclosed in a tag. 17 As
- * we know, every feed begins with these lines: Feed Name.....
- * 18 so we should skip the tag which is a child of , 19 and
- * take in consideration only tag which is a child of 20
- *
- * 21 In order to achieve this, we will make use of a boolean
- * variable. 22
- */
- boolean insideItem = false;
- // Returns the type of current event: START_TAG, END_TAG, etc..
- int eventType = xpp.getEventType();
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- if (xpp.getName().equalsIgnoreCase("item")) {
- insideItem = true;
- } else if (xpp.getName().equalsIgnoreCase("title")) {
- if (insideItem)
- headlines.add(xpp.nextText()); // extract the
- // headline
- } else if (xpp.getName().equalsIgnoreCase("link")) {
- if (insideItem)
- links.add(xpp.nextText()); // extract the link
- // of
- // article
- } else if (xpp.getName()
- .equalsIgnoreCase("description")) {
- if (insideItem)
- des.add(xpp.nextText()); // extract the link of
- // article
- }
- } else if (eventType == XmlPullParser.END_TAG
- && xpp.getName().equalsIgnoreCase("item")) {
- insideItem = false;
- }
- eventType = xpp.next(); // move to next element
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (XmlPullParserException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return links;
- }
- @Override
- protected void onPostExecute(ArrayList<String> result) {
- Log.d(TAG, "entered onpostExceute ");
- // Binding data
- Log.d(TAG, "" + headlines);
- adapter = new SpecialAdapter(con, headlines, des);
- OnTvRss.list.setAdapter(adapter);
- Log.d(TAG, "entered listener ");
- Log.d(TAG, " " + list);
- }
- }
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
- Uri uri = Uri.parse(links.get(arg2));
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(uri);
- con.startActivity(intent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement