• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Java/Android Help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Nechen

Member
Joined
Dec 15, 2009
I'm currently working on some projects to get my bearings with programming for Android.

I'm currently using the 1.6 API (4), figure it'll run on any phone at that point. Anyway I've managed to get the hang of activities, classes, and layouts.

At this point I'm able to produce text on the screen with custom fonts (.ttf) and even change the color with hex values and I need to know if this is possible.

When I used to make maps for Starcraft back in the day there was a way to create text that would "type" itself onto the screen, as if someone were typing it with a keyboard instead of just having it pop up like this:

1.) TEXT!
2.) T...E...X...T...!


I'm not familiar with Java and I was wondering if this is even possible, to somehow tell TextView to populate each character with a 500-1000ms delay?
 
I'm not aware of such option on a TextView.
You'll have to setup up a timer, and update the text manually.

I haven't tested it, but it should be something along these lines:
Code:
        Timer timer = new Timer();
        timer.schedule(new UpdateText("Text", myTextView), 100, 200);

Code:
    class UpdateText extends TimerTask
    {
        private int index;
        private String inputString;
        private TextView textView;

        public UpdateText(String inputString, TextView textView)
        {
            this.inputString = inputString;
            this.textView = textView;
        }

        @Override
        public void run()
        {
            if (this.index < this.inputString.length())
            {
                this.textView.setText(this.inputString.substring(0, ++this.index));
            }
        }
    }
 
Timer class seems like a somewhat interesting way of doing it, but the scheduling might be a pain. Why not just kick off another thread that does the updating one character at a time, with a pause to sleep in between updates? Seems easier than trying to fit that weird operation into the way the timer works.
 
^ This would probably be a better idea than what I posted, cleaner and more readable as well.
 
Back