Reputation:
Im trying to animate the three dots of "Loading..." textview as follows,
Handler handler = new Handler();
for (int i = 100; i <= 3500; i =i+100) {
final int finalI = i;
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(finalI %300 == 0){
loadigText.setText("Loading.");
}else if(finalI %200 == 0){
loadigText.setText("Loading..");
}else if(finalI %100 == 0){
loadigText.setText("Loading...");
}
}
}, i);
The problem is that , 1. Im unable to animate it infinitely till the dialog is visible. 2. Im unable to reduce the speed of Three dots animation,
How can I be able to sort this out
Upvotes: 3
Views: 3875
Reputation: 1586
Example:
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
int count = 0;
@Override
public void run() {
count++;
if (count == 1)
{
textView.setText("Loading.");
}
else if (count == 2)
{
textView.setText("Loading..");
}
else if (count == 3)
{
textView.setText("Loading...");
}
if (count == 3)
count = 0;
handler.postDelayed(this, 2 * 1000);
}
};
handler.postDelayed(runnable, 1 * 1000);
Upvotes: 12