2014-05-22 6 views
2

xml에서 제목과 설명을 표시하는 RSS 피드 앱이 있습니다. xml을 파싱하고 webview 내부에 내용을 표시합니다. 내가 webview로 이동할 때, 나는 내용을 스크롤 할 수 없다. 그것은 정적 인 것과 같습니다. webview에서 내용을 스크롤하는 방법이 있습니까?Google Glass에서 웹보기를 스크롤하는 방법

웹보기 :

title = (TextView) findViewById(R.id.title); 
     desc = (WebView) findViewById(R.id.desc); 

     // set webview properties 
     WebSettings ws = desc.getSettings(); 
     ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
     ws.getPluginState(); 
     ws.setPluginState(PluginState.ON); 
     ws.setJavaScriptEnabled(true); 
     ws.setBuiltInZoomControls(true); 

     // Set the views 
     title.setText(feed.getItem(pos).getTitle()); 

     desc.loadDataWithBaseURL("http://www.googleglass.gs/", feed 
       .getItem(pos).getDescription(), "text/html", "UTF-8", null); 

구문 분석 :

public class DOMParser { 

    private RSSFeed _feed = new RSSFeed(); 

    public RSSFeed parseXml(String xml) { 

     URL url = null; 
     try { 
      url = new URL(xml); 
     } catch (MalformedURLException e1) { 
      e1.printStackTrace(); 
     } 

     try { 
      // Create required instances 
      DocumentBuilderFactory dbf; 
      dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 

      // Parse the xml 
      Document doc = db.parse(new InputSource(url.openStream())); 
      doc.getDocumentElement().normalize(); 

      // Get all <item> tags. 
      NodeList nl = doc.getElementsByTagName("item"); 
      int length = nl.getLength(); 

      for (int i = 0; i < length; i++) { 
       Node currentNode = nl.item(i); 
       RSSItem _item = new RSSItem(); 

       NodeList nchild = currentNode.getChildNodes(); 
       int clength = nchild.getLength(); 

       // Get the required elements from each Item 
       for (int j = 1; j < clength; j = j + 2) { 

        Node thisNode = nchild.item(j); 
        String theString = null; 
        String nodeName = thisNode.getNodeName(); 

        theString = nchild.item(j).getFirstChild().getNodeValue(); 

        if (theString != null) { 
         if ("title".equals(nodeName)) { 
          // Node name is equals to 'title' so set the Node 
          // value to the Title in the RSSItem. 
          _item.setTitle(theString); 
         } 

         else if ("content:encoded".equals(nodeName)) { 
          _item.setDescription(theString); 

          // Parse the html description to get the image url 
          String html = theString; 
          org.jsoup.nodes.Document docHtml = Jsoup 
            .parse(html); 
          Elements imgEle = docHtml.select("img"); 
          _item.setImage(imgEle.attr("src")); 
         } 

         else if ("pubDate".equals(nodeName)) { 

          // We replace the plus and zero's in the date with 
          // empty string 
          String formatedDate = theString.replace(" +0000", 
            ""); 
          _item.setDate(formatedDate); 
         } 

        } 
       } 

       // add item to the list 
       _feed.addItem(_item); 
      } 

     } catch (Exception e) { 
     } 

     // Return the final feed once all the Items are added to the RSSFeed 
     // Object(_feed). 
     return _feed; 
    } 

} 
+0

이 문제는 다른 작성자가 ListView에서 해결했습니다.이 코드를 적용하려고 시도한 적이 있습니까? https://github.com/pscholl/glass_snippets/tree/master/imu_scrollview –

+0

ListView 용입니다. 하지만 webview를 묻는 중 – user3602987

답변

2

당신은 당신의 자신의 웹보기를 구현하고 그 기능을 구현해야하거나 텐트와 기본 구글 유리 웹 브라우저를 사용할 수 있습니다.

편집 : 당신은 또한 의도로 기본 웹 브라우저를 사용하려고 할 수 있습니다

Intent intent = new Intent(Intent.ACTION_VIEW); 
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString()); 
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 
intent.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity"); 
intent.setDataAndType(Uri.fromFile(file),mimetype); 
startActivity(intent); 

당신은 당신의 XML의 내용으로 HTML 파일을 작성, 당신은 SDCARD에 저장하고 당신이 의도를 열 .

+0

Mark Scheel이 제공 한 샘플 코드를 보았습니다. 거기에 머리 움직임 ListView 구현되었습니다. 그래서, 여기에 webView 구현해야합니까? – user3602987

+1

해당 솔루션을 사용할 수 있지만 페이지가 너무 길면 목이 어떻게되는지 생각해야합니다! 네이티브 웹 브라우저와 유사한 기능을 구현하려고합니다. 왼쪽/오른쪽으로 페이지를 스크롤하면 – Bae

+0

입니다. 2 일간 갇혀있다. 나는 이것을위한 해결책을 찾을 수 없다. 내 웹 페이지가 정적입니다. Google 유리에서 어떤 작업도하지 않았습니다. – user3602987

관련 문제