Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1000405 // Android on-screen log test (log, class Lg)

JavaX source code (Android) - run with: the app

import android.widget.*;
import android.view.*;
import android.content.Context;
import android.app.Activity;
import java.util.Timer;
import java.util.TimerTask;

public class main {
  static class Lg {
    ScrollView sv;
    TextView tv;
    StringBuilder buf = new StringBuilder();
    
    Lg(Activity context) {
      sv = new ScrollView(context);
      tv = new TextView(context);
      tv.setText(buf.toString());
      sv.addView(tv);
    }
    
    View getView() {
      return sv;
    }
    
    void print(String s) {
      buf.append(s);
      tv.setText(buf.toString());
    }
    
    void println(String s) {
      print(s + "\n");
    }
  }
  
  static Lg log;
  
  public static View main(final Activity context) {
    log = new Lg(context);
    Timer myTimer = new Timer();
    myTimer.schedule(new TimerTask() {          
      public void run() {
        context.runOnUiThread(new Runnable() {
          public void run() {
            log.println("More text");
          }
        });
      }
    }, 0, 1000);
    
    return log.getView();
  }
}

Author comment

Began life as a copy of #1000404

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000405
Snippet name: Android on-screen log test (log, class Lg)
Eternal ID of this version: #1000405/1
Text MD5: db27aaf6ca8f253bf729521aef61c2a1
Author: stefan
Category: javax android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-03 03:04:17
Source code size: 1119 bytes / 52 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 627 / 550
Referenced in: #1000406 - Android redirecting System.out and System.err to screen test
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)