【问题标题】:How to parse xml data to display on web view如何解析 xml 数据以显示在 Web 视图上
【发布时间】:2013-12-12 07:36:00
【问题描述】:

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

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);

        } 
    });

【问题讨论】:

  • 您想在 Web 视图中使用 headlineArticleDateBody 吗?
  • 无法理解您想要什么!
  • 是的。我想在 webview @dmsherazi 中使用标题、文章日期和正文

标签: android android-layout android-intent android-listview


【解决方案1】:

使用这段代码,这里的前三行是从其他活动中获取你传递的数据。然后,您将使用这些字符串来创建 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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多