I want to make an application that will grab the HTML from a website and display certain strings all inside the app in a linear layout. (I do not want to use webView). The data that I am retrieving changes every day; however the format is generally the same; different in only the amount of items on the page.
I am able to use jSoup (in an Async Task) to retrieve and parse the strings that I need. I also can make the string pop up in a toast message; so I can confirm that I am getting the string that I want.
My question is how I can actually display the strings in the app?
There are two different items I want to display. A name, and then a description below it.
Example:
(Name) FRENCH FRIED SHRIMP
(Description) Twelve shrimp lightly breaded with Japanese style bread crumbs and deep fried to golden brown. Served with cocktail sauce ONLY $12.49
Below is the Code that is currently displaying a string that I want.
protected void onPostExecute(Document doc) {
Toast.makeText(RoundtheClockActivity.this, doc.select("p").get(0).toString(), Toast.LENGTH_SHORT).show();
}
Right now I am going to want to change views to another page.. And I suppose String1 is what I want to display… Code below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/soupSpecial1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.01"
android:text="@string/string1" />
</LinearLayout>
To add, originally I have one view; but after I do the async task; I want to change to a new view. That will display the String.
public void onClick(View v) {
try {
new DownloadTask().execute("url");
} catch (Exception e) {
//logic for exception here
}
initialize your TextView in your app as below:
and in your Async Task’s onPostExecute, do the following: