Reputation: 450
I want to display button or textview step by step after few second once user click on button with tts. For instance :
A -----> AB-----> ABC---> Image.. a -----> ab-----> abc---> Image..
all have different text view means 4 text view
I have invisible all the elements want to show and set visible during tun time but it is not working as expected and even dont think it is right solution.
public void playRow1(View v) {
mytexts = (Button)findViewById(R.id.btn3Img);
handler.postDelayed(new Runnable(){
@Override
public void run() {
for(int i=0; i < 3; i++){
if(i == 0){
Button btn1 = (Button) findViewById(R.id.btn3Img);
Button btn2 = (Button) findViewById(R.id.btn3Img2);
Button btn3 = (Button) findViewById(R.id.Button01);
ImageView btnImg1 = (ImageView) findViewById(R.id.imgObjRow1);
ImageView btnImg2 = (ImageView) findViewById(R.id.imgPlayNextRow1);
btn1.setVisibility(View.VISIBLE);
btn2.setVisibility(View.VISIBLE);
btnImg1.setVisibility(View.VISIBLE);
btn3.setVisibility(View.VISIBLE);
tts.speak("a ", TextToSpeech.QUEUE_FLUSH, null);
btnImg2.setVisibility(View.INVISIBLE);
try{
Thread.sleep(3000);
}catch(Exception e){
}
}
}, 2000 * (count + 1));
}
I believe the run method should be in loop but that was not working.... Please help me to provide some solution for displaying text in steps..
thanks in advance. itin
Upvotes: 0
Views: 604
Reputation: 38098
I just tested a (single TextView) solution which works just fine.
It looks like this:
TextView txt = (TextView) findViewById(R.id.txtTitle);
final String str = "Some Text";
final int secs = str.length();
new CountDownTimer((secs + 1) * 1000, 1000) // Tick length: 1 second
{
int sec = 0;
@Override
public final void onTick(final long millisUntilFinished)
{
txt.setText(txt.getText().toString() + str.charAt(sec));
sec += 1;
}
@Override
public void onFinish()
{
// TODO Auto-generated method stub
}
}.start();
This code goes after your setContentView (in your onCreate() method), and assumes your layout having a TextView called txtTitle
.
Similarly, you can do with any other TextView.
[UPDATE]
This is how to do the same, but with 2 TextViews. The second starts "typing" after the first one has finished:
final TextView txt = (TextView) findViewById(R.id.txtTitle);
final TextView txt2 = (TextView) findViewById(R.id.txtTitle2);
final String str = "Some Text";
final String str2 = "Another Text";
//init();
final int secs = str.length();
new CountDownTimer((secs + 1) * 1000, 1000)
{
int sec = 0;
@Override
public final void onTick(final long millisUntilFinished)
{
txt.setText(txt.getText().toString() + str.charAt(sec));
sec += 1;
}
@Override
public void onFinish()
{
final int secs = str2.length();
// Start the second CountDownTimer
new CountDownTimer((secs + 1) * 1000, 1000)
{
int sec = 0;
@Override
public final void onTick(final long millisUntilFinished)
{
txt2.setText(txt2.getText().toString() + str2.charAt(sec));
sec += 1;
}
@Override
public void onFinish()
{
// TODO Auto-generated method stub
}
}.start();
}
}.start();
You can easily extend the concept to as many TextViews you want, just start the next CountDownTimer in the onFinish()
method of the previous one.
Upvotes: 1