如何解析xml数据以在Web视图上显示

如何解析xml数据以在Web视图上显示

问题描述:

我想将列表视图中的数据转到webview。如何在Web视图中显示xml解析? 这是从列表视图我的代码的意图:如何解析xml数据以在Web视图上显示

list=(ListView)findViewById(R.id.list); 


    // Getting adapter by passing xml data ArrayList 
    adapter=new LazyAdapter(this, songsList);   
    list.setAdapter(adapter); 

    list.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { 
      // getting values from selected ListItem 
      String Headline = ((TextView) v.findViewById(R.id.title)).getText().toString(); 
      String ArticleDate = ((TextView) v.findViewById(R.id.date)).getText().toString(); 
      String Body = ((TextView) v.findViewById(R.id.body)).getText().toString(); 

      // Starting new intent 
      Intent in =new Intent(); 
      in.setClass(news.this.getApplicationContext(), SingleMenuItemActivity.class); 
      Log.i(KEY_HEADLINE, Headline); 
      Log.i(KEY_ARTICLEDATE, ArticleDate); 

       in.putExtra(KEY_HEADLINE, Headline);     
       in.putExtra(KEY_ARTICLEDATE, ArticleDate); 
       in.putExtra(KEY_BODY, Body); 
      startActivity(in); 

     } 
    }); 
+0

是否要在Web视图中使用'headline','ArticleDate'和'Body'? – dmSherazi

+0

不明白你想要什么! – Naddy

+0

是的。我想用标题,ArticleDate和Body在webview @dmsherazi – user3086099

使用此代码,这里的前三行是获得体U从其他活动传递数据。然后,您将使用这些字符串以HTML格式创建一个字符串。最后一行代码将显示在一个webView中。 (希望这会有所帮助)

String Headline = getIntent().getExtras().getString(KEY_HEADLINE); 
String ArticleDate = getIntent().getExtras().getString(KEY_ARTICLEDATE); 
String Body = getIntent().getExtras().getString(KEY_BODY); 


String html="<html><body><h1>"+Headline+"</h1><h4> Date:"+ArticleDate+"</hr><p>"+ 
      Body+"</p></body></html>"; // use HEadline ,Article date and body here 
WebView webview = null; 
webview.loadData(html, "text/html", "utf-8");