I have recently developed an android app, which is parsing the xml links, whenever i use the app it responds very slowly, because each time i open the app and navigate the pages on the app, it parse it then give the data,
is there any way so that i could speed up the app, i have searched for it on google, but have not got any idea, it stated to use the volley library, but no result as i am unable to use that,
plz help guys if anyone has any option , is there any way that i could parse the link and store it into the cache and then retrive from there..
package com.stepupup.pm;
import info.stepupup.tabswipe.R;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class Cricket extends ListFragment {
static final String URL = "http://www.statenewsonline.com/category/sports/cricket/feed";
// XML node keys
static final String KEY_ITEM = "item"; // parent node
static final String KEY_NAME = "title";
static final String KEY_COST = "link";
static final String KEY_DESC = "content:encoded";
static final String KEY_PUB = "pubDate";
Context context;
Typeface font;
String nam,cost,desc,ti,cdesc,lnk1;
TextView t1;;
TextView t2,t3,t5,t15;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.cricket, container, false);
font=Typeface.createFromAsset(getActivity().getAssets(), "DroidHindi.ttf");
return rootView;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
// looping through all item nodes <item>
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_NAME, (parser.getValue(e, KEY_NAME)));
map.put(KEY_COST, parser.getValue(e, KEY_COST));
map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
map.put(KEY_PUB, parser.getValue(e, KEY_PUB));
// map.put(KEY_CDESC, parser.getValue(e, KEY_CDESC));
// adding HashList to ArrayList
menuItems.add(map);
}
ListAdapter adapter = new SimpleAdapter(getActivity(), menuItems,
R.layout.list_item,
new String[] { KEY_NAME, KEY_DESC,KEY_COST}, new int[] {
R.id.name1, R.id.description, R.id.link1}){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewGroup view = (ViewGroup) super.getView(position, convertView, parent);
if(convertView == null) Cricket.setAppFont(view, font);
t1=(TextView)view.findViewById(R.id.name1);
t1.setTypeface(font);
t2=((TextView)view.findViewById(R.id.description));
t2.setTypeface(font);
t15=(TextView)view.findViewById(R.id.link1);
t15.setTypeface(font);
return view;
}
};
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
t1=(TextView)view.findViewById(R.id.name1);
nam=t1.getText().toString();
t2=((TextView)view.findViewById(R.id.description));
desc = t2.getText().toString();
t15=(TextView)view.findViewById(R.id.link1);
lnk1=t15.getText().toString();
// cost = ((TextView) view.findViewById(R.id.cost)).getText().toString();
ti = ((TextView) view.findViewById(R.id.time)).getText().toString();
// Starting new intent
Intent in = new Intent(getActivity(), SingleMenuItemActivity.class);
in.putExtra(KEY_NAME, nam);
in.putExtra(KEY_COST, lnk1);
in.putExtra(KEY_DESC, desc);
in.putExtra(KEY_PUB, ti);
startActivity(in);
}
});
}
protected static void setAppFont(ViewGroup view, Typeface font2) {
// TODO Auto-generated method stub
}
}
and the folllwing is my xml file..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>