This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<TextView | |
android:id="@+id/myTextView" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_centerVertical="true" | |
android:text="@string/hello_world" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myfirstapp; | |
import android.os.Bundle; | |
import android.os.AsyncTask; | |
import android.app.Activity; | |
import android.view.Menu; | |
import android.widget.TextView; | |
import android.util.Log; | |
import android.widget.ImageView; | |
import java.io.IOException; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
import org.jsoup.select.Elements; | |
public class MainActivity extends Activity { | |
private static final String TAG = "Hello"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
new MyTask().execute(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
private class MyTask extends AsyncTask<Void, Void, String> { | |
@Override | |
protected String doInBackground(Void... params) { | |
String url = "http://stocks.finance.yahoo.co.jp/stocks/detail/?code=7203.T"; | |
String arg1 ="0"; | |
String arg2 ="0"; | |
try{ | |
Document doc = Jsoup.connect(url).get(); | |
Elements stoksPrices=doc.select("td[class=stoksPrice]"); | |
Elements reals=doc.select("dd[class=yjSb real]"); | |
for (Element stoksPrice : stoksPrices){ | |
System.out.println(stoksPrice.text()); | |
arg2 =stoksPrice.text(); | |
System.out.println(arg2.replace(",","")); | |
arg2=(arg2.replace(",","")); | |
} | |
for (Element real : reals){ | |
System.out.println(real.child(0).text()); | |
arg1 = real.child(0).text(); | |
} | |
} catch (Exception e) { | |
Log.e(TAG, "ERROR"+e.toString()); | |
arg2=e.toString(); | |
e.printStackTrace(); | |
} | |
return arg1+ " " + arg2; | |
} | |
@Override | |
protected void onPostExecute(String result) { | |
((TextView)findViewById (R.id.myTextView)).setText (result); | |
} | |
} | |
} | |
0 件のコメント:
コメントを投稿