Hello,
I am working with Android. Can anybody tell me how can i create something like... When i click one button once....numerical digits will show me automatically as increasing order like 1,2,3,4......so on with switched between two digits, after every 5 sec...I mean it shows only latest one digits like counter.
I tried with this
public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory {
private TextSwitcher mSwitcher;
private int mCounter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_switcher_1);
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
// Button nextButton = (Button) findViewById(R.id.next); // nextButton.setOnClickListener(this);
updateview();
}
public void hi() {
mCounter++;
mSwitcher.setText(String.valueOf(mCounter));
mSwitcher.addView(makeView());
}
private void updateview() {
int delay = 5000; // delay for 5 sec.
int period = 5000; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
//private View v;
public void run() {
// Task here ...
hi();
Log.d("Android", "hi value : " + mCounter);
}
}, delay, period);
}
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
Log.d("Android", "makeView value : " + mCounter);
return t;
}
}
Please i need help..for my project work. Thanks in advance.