Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- String VersioRemota;
- String Temp;
- TextView Tv1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate ( savedInstanceState );
- setContentView ( R.layout.activity_main );
- new Thread(new Runnable(){
- @Override
- public void run(){
- URL url = null;
- try {
- url = new URL("http://www.inforatge.com/alzira/main/wdl/clientraw.txt");
- BufferedInputStream bis = new BufferedInputStream(url.openStream());
- byte[] buffer = new byte[730];
- int bytesRead = 0;
- bytesRead = bis.read(buffer);
- VersioRemota = new String(buffer, 0, bytesRead);
- String Datos[] = VersioRemota.split(" ");
- Temp = Datos[4];
- bis.close();
- } catch (MalformedURLException e) {
- Log.w("", "MALFORMED URL EXCEPTION");
- } catch (IOException e) {
- Log.w(e.getMessage(), e);
- }
- }
- }).start();
- Tv1=(TextView) findViewById ( R.id.TextView1 );
- Tv1.setText(Temp);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:id="@+id/TextView1"
- android:layout_width="180dp"
- android:layout_height="61dp"
- android:layout_marginStart="116dp"
- android:layout_marginLeft="116dp"
- android:layout_marginTop="80dp"
- android:text="temperatura"
- android:textSize="30sp"
- android:textStyle="bold"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- tools:textColor="@color/colorPrimaryDark" />
- public class MainActivity extends AppCompatActivity {
- String VersioRemota;
- String Temp;
- TextView Tv1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Tv1 = (TextView) findViewById(R.id.txtPrueba);
- new Thread(new Runnable() {
- @Override
- public void run() {
- URL url = null;
- try {
- url = new URL("https://www.inforatge.com/alzira/main/wdl/clientraw.txt");
- BufferedInputStream bis = new BufferedInputStream(url.openStream());
- byte[] buffer = new byte[730];
- int bytesRead = 0;
- bytesRead = bis.read(buffer);
- VersioRemota = new String(buffer, 0, bytesRead);
- String Datos[] = VersioRemota.split(" ");
- Temp = Datos[4];
- runOnUiThread(new Runnable() {
- public void run() {
- Tv1.setText(Temp);
- }
- });
- bis.close();
- } catch (MalformedURLException e) {
- Log.w("error**", "MALFORMED URL EXCEPTION");
- } catch (IOException e) {
- Log.w(e.getMessage(), e);
- }
- }
- }).start();
- //
- //Tv1.setText(Temp);
- }
- }
Add Comment
Please, Sign In to add comment