우선 제가 다른분들이 올려주신거 참고해서 이렇게 짜봤습니다.
보라색부분이 몇고간격으로 자동으로 바뀌게 하는 부분입니다~~
뭐가 문젤까요? ㅜㅜㅜ
package android.OpenMe;
//import com.android.helloworld.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
public class OpenMe extends Activity implements ViewFactory {
private TextSwitcher timeSwitcher;
static int flowTime;
static int oldTime;
static int Time;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer player = MediaPlayer.create(this, R.raw.test);
player.start();
oldTime = (int)System.currentTimeMillis()/5000;
timeSwitcher = (TextSwitcher) findViewById(R.id.time_switcher);
timeSwitcher.setFactory(this);
timeSwitcher.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
OpenMe.this.nextText();
}
});
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
timeSwitcher.setInAnimation(in);
timeSwitcher.setOutAnimation(out);
timeSwitcher.setText("1초");
}
protected void nextText() {
Time=0;
String str;
while(Time<10)
{
flowTime = (int)System.currentTimeMillis()/5000;
if(flowTime != oldTime) //기준시간과 현재시간을 비교해서 다르면 Time증가시키고 기준시간을 현재시간으로 update.
{
Time++;
oldTime = flowTime;
str = String.valueOf(Time);
timeSwitcher.setText(str);
}
}
}
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
}
핸들러를 이용하세요.
Handler 검색 ㄱㄱㄱ