首先请检查 * 谷歌浏览器中的网址* http://mobileecommerce.site247365.com/admin/catdata.xml。我面临两个问题 1。来自xml的第二个 cat_desc cat_name E n I Sept 没有在webview上显示。我认为这是因为在其cat_desc在表格样式标记的第一行包含%符号<“table style =”border-collapse:collapse; width :100%;“>如何忽略%sign?
2 。第二个问题是,从上一个带有 cat_name讲义的thrid标记解析时出现问题 cat_desc 。它不会完全解析,它的最后三行没有被解析。我也会在日志中检查它,但最后三行不是paresd。为什么会这样?对于其他cat_desc解析得非常好并且在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);
}
}
答案 0 :(得分:1)
我已经离开了这个URl: -
http://mobileecommerce.site247365.com/admin/catdata.xml"
并发现您必须进行非常小的更改,使用px而不是%..作为webview,也不支持%age符号。 希望它有所帮助.. :)