2016-04-01 4 views
-1

Scraping Daten aus einer HTML-Datei und wenn ich meine App den Standardbildschirm nur erscheint. Sag mir nicht, dass ich den jsoup doc lesen soll, lies alles schon. Hat jemand eine Idee, wie man es auf dem Bildschirm drucken lassen?Scraped Daten nicht drucken - Android Studio

import android.app.Activity; 
    import android.os.Bundle; 
    import java.io.File; 
    import java.io.IOException; 
    import org.jsoup.Jsoup; 
    import org.jsoup.nodes.Document; 
    import org.jsoup.nodes.Element; 
    import org.jsoup.select.Elements; 
    import android.widget.TextView; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    try { 
     File input = new File("C:\\Users\\user\\Desktop\\Mobile Newest\\JSoup\\app\\src\\main\\assets\\filename.html"); 
     Document doc = Jsoup.parse(input, "UTF-8"); 
     Elements tableElements = doc.select("td"); 
     TextView textView = (TextView)findViewById(R.id.text_view); 
     for (Element td : tableElements) { 
      textView.setText(td.text()); 
      System.out.println(td.text()); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    //System.out.println("Testing"); 
} 

} Aktivität Haupt

<android.support.design.widget.AppBarLayout  android:layout_height="wrap_content" 
    android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 
     android:layout_width="match_parent" android:layout_height="? attr/actionBarSize" 
     android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton android:id="@+id/fab" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end"   android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email" /> 

Inhalt Haupt

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:showIn="@layout/activity_main" tools:context=".MainActivity"> 

<TextView android:text="Hello World!" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

+0

den Bildschirm ??? –

+0

Es ist der Hauptaktivitätsbildschirm, es sagt nur "Hallo Welt" anstelle der Daten, die ich – DW41

+0

Post 'activity_main 'geschabt habe. –

Antwort

0

Wie zu kommentieren auf Frage:

Wenn Sie irgendeine Mitteilung zu TextView zeigen möchten, dann erhalten Sie es ist Referenz und setzen Sie Text darauf.

TextView textView = (TextView)findViewById(R.id.text_view); 

for (Element td : tableElements) { 
    textView.setText(td.text()); 
} 

eine ID definieren für Ihre TextView in content_main:

<TextView 
    android:id="@+id/text_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
+0

hinzugefügt in, immer noch nicht zu drucken, sobald ich laufe die App auf meinem Handy – DW41

+0

Post 'MainActivity' Code. –

+0

gerade dort bearbeitet – DW41