Ich scrapping Daten von einer lokalen HTML-Seite in Android Studio und anstelle der richtigen Informationen wird alles scrapped, dass seine Anzeige "text_view". Wer weiß, wie man die Daten anzeigt, die ich gekratzt habe? Unten ist ein Hauptcode.Android - Anzeigen der falschen Info für meine App
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();
}*/
try {
StringBuilder buf=new StringBuilder();
InputStreamReader inputStream = new InputStreamReader(getAssets().open("filename.html"));
BufferedReader bufferedReader = new BufferedReader(inputStream);
String str;
while ((str=bufferedReader.readLine()) != null) {
buf.append(str);
}
Document doc = Jsoup.parse(buf.toString());
//other code parts goes next
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();
}
}
Unten ist die content_main.xml
<?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="text_view1"
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
andere Code-Teile? Elemente tableElements = doc.select ("td"); TextView Textansicht = (TextView) findViewById (R.id.text_view); für (Element td: tableElements) { textView.setText (td.text()); System.out.println (td.text()); } das meinst du? – DW41
Ich aktualisierte meinen Hauptcode über – DW41
Ich meinte, dass das Problem im Pfad der Datei war, so dass Sie die Datei nicht lesen und Ihre Textansicht wird nicht festgelegt. Eine andere Sache ist, dass nur das letzte Tabellenelement gesetzt wird. Und System.out.println funktioniert nicht in Android, verwenden Sie stattdessen Log.d, um Ihre analysierten Elemente in Logcat zu sehen. – thekekc