Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Created September 3, 2010 14:46
Show Gist options
  • Save johnlindquist/563969 to your computer and use it in GitHub Desktop.
Save johnlindquist/563969 to your computer and use it in GitHub Desktop.
package com.johnlindquist;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Random;
import java.util.TimerTask;
public class HelloAndroid extends Activity
{
public Handler handler;
public TextView viewById;
private ScrollView scrollView;
private LinearLayout linearLayout;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
scrollView = new ScrollView(this);
linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout);
handler = new Handler();
UpdateText updateText = new UpdateText(this);
setContentView(scrollView);
handler.postDelayed(updateText, 100);
}
private class UpdateText extends TimerTask
{
private Context context;
private UpdateText(Context context)
{
this.context = context;
}
@Override
public void run()
{
ArrayList names = new ArrayList();
names.add("John");
names.add("Mindy");
names.add("Ben");
names.add("Scootie");
String name = (String) names.get(new Random().nextInt(names.size()));
TextView textView = new TextView(context);
textView.setText("Hello, " + name);
linearLayout.addView(textView);
handler.postDelayed(this, 100);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment