Issue
Firstly please check url*http://mobileecommerce.site247365.com/admin/catdata.xml in* google chrome. I am facing two problems 1. For second cat_desc from xml having cat_name E n I Sept not showing on webview .I think it is because in its cat_desc contains % sign on first line in table style tag <"table style="border-collapse:collapse;width :100%;">How to ignore % sign?
2.Second problem is that, from last thrid tag with cat_name Handouts creating problem while parsing it cat_desc.It will not parse completely, its last three lines are not parsed .I will check it in log also,but last three lines are not paresd.Why is it so ?For other cat_desc are parsed very well and well working on webview.
public class FirstActivity extends ListActivity implements OnItemClickListener {
/** called when the activity is first created. */
String[] cat_name=null;
String[] cat_desc=null;
ListView optionslist=null;
NewsListAdapter adapter=null;
ArrayList<NewsItem> getArray=null;
ArrayAdapter<String> arrayadapter=null;
HashMap<String, String> hashamp=null;
public static final String url="http://mobileecommerce.site247365.com/admin/catdata.xml";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
innitializeUIComponents();
new RefreshArrayFromInternet().execute(url);
}
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Log.v("in position", ""+position);
String str=new String(getArray.get(position).getCatdesc());
Log.v("on item click desc", str);
Intent intent=new Intent(FirstActivity.this, WebviewActivity.class);
intent.putExtra("str",str);
startActivity(intent);
}
private void innitializeUIComponents()
{
optionslist=getListView();
optionslist.setOnItemClickListener(this);
}
private class RefreshArrayFromInternet extends AsyncTask<String,Void,ArrayList<NewsItem>>
{
@Override
protected ArrayList<com.example.vidushi.NewsItem> doInBackground(
String... params) {
Log.v("Thread started","parsing thread has started!!!");
final ArrayList<NewsItem> newsList=new ArrayList<NewsItem>();
try
{
URL urlexec=new URL(params[0]);
URLConnection connection=urlexec.openConnection();
InputStream input=connection.getInputStream();
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser parser=factory.newSAXParser();
parser.parse(input,new DefaultHandler(){
boolean itemTagStarted=false;
String currentTag="";
StringBuffer buffer;
NewsItem item=null;
@Override
public void startDocument() throws SAXException {
Log.v("parsing started!!!","parsing started!!!");
}
@Override
public void startElement(String uri, String localName,String qName, Attributes attributes)
throws SAXException {
currentTag=localName;
Log.v("in start elelmet", "in start elelmet");
if(qName.equals("Table"))
{
buffer=new StringBuffer();
itemTagStarted=true;
item=new NewsItem();
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if(itemTagStarted)
{
if(currentTag.equals("Cat_Name"))
{
item.setCatname(String.valueOf(ch,start,length));
}
if(currentTag.equals("Cat_id"))
{
item.setCatid(String.valueOf(ch,start,length));
}
if(currentTag.equals("Cat_Desc"))
{
buffer.append(String.valueOf(ch,start,length));
}
}
}
@Override
public void endElement(String uri, String localName,
String qName) throws SAXException {
currentTag="";
if(qName.equals("Table"))
{
itemTagStarted=false;
newsList.add(item);
}
if(qName.equals("Cat_Desc"))
{
item.setCatdesc(buffer.toString());
Log.v("Description data",buffer.toString());
}
}
@Override
public void endDocument() throws SAXException {
Log.v("parsing completed","parsing completed : array size : "+newsList.size());
}
});
}
catch(Exception ex)
{
ex.printStackTrace();
}
return newsList;
}
@Override
protected void onPostExecute(ArrayList<NewsItem> result) {
super.onPostExecute(result);
getArray=result;
if(result.size()==0)
{
Toast.makeText(FirstActivity.this,"There is some problem with the internet connection or the specified url!!!",Toast.LENGTH_LONG).show();
}
String[] array=new String[result.size()];
cat_desc=new String[result.size()];
Log.v("resukt size",""+result.size());
for(int i=0;i<result.size();i++)
{
array[i]=result.get(i).getCatname();
}
arrayadapter=new ArrayAdapter<String>(FirstActivity.this,android.R.layout.simple_list_item_1,array);
optionslist.setAdapter(arrayadapter);
}
}
Solution
I have gone this URl:-
http://mobileecommerce.site247365.com/admin/catdata.xml"
and find out that you have to make very small changes that use px instead of %.. as webview nor support %age symbol.. Hope it helps.. :)
Answered By - mAc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.