我一直在尝试让我的应用程序移动到下一个类“GameOver.class”。有人可以指出我做错了什么吗?根据我的日志, OnAnimationEnd 方法甚至没有被击中。如果我将其用作主类,则 GameOver 类确实可以工作。
public class Rocky extends Activity implements AnimationListener {
TextView m_dog, m_spoon, m_ice_cream, m_car, m_giraffe ;
ImageView rocky_pic, dog, spoon,ice_cream, car, giraffe;
Animation animationFadeOut, animationFadeIn,viewObjFades;
int count = 0;
MediaPlayer mp;
private static final String TAG = "MyActivity";
AlertDialog.Builder builder;
AlertDialog alertDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rocky);
rocky_pic = (ImageView)findViewById(R.id.rocky_pic);
Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
rocky_pic.startAnimation(animationFadeIn);
m_car=(TextView) findViewById(R.id.m_car);
m_dog=(TextView) findViewById(R.id.m_dog);
m_spoon=(TextView) findViewById(R.id.m_spoon);
m_ice_cream=(TextView) findViewById(R.id.m_ice_cream);
m_giraffe=(TextView) findViewById(R.id.m_giraffe);
dog = (ImageView) findViewById(R.id.dog);
spoon = (ImageView) findViewById(R.id.spoon);
ice_cream = (ImageView) findViewById(R.id.ice_cream);
car = (ImageView) findViewById(R.id.car);
giraffe = (ImageView) findViewById(R.id.giraffe);
mp = MediaPlayer.create(Rocky.this, R.raw.ding);
dog.setAlpha(0);
spoon.setAlpha(0);
ice_cream.setAlpha(0);
car.setAlpha(0);
giraffe.setAlpha(0);
}
@Override
public void onStart() {
super.onStart();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Text.text.text");
builder = new AlertDialog.Builder(this);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.setCanceledOnTouchOutside(true);
ice_cream.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
ice_cream.setAlpha(200);
count ++;
mp.start();
ice_cream.setClickable(false);
if (count==5){
fadeout();
}
}
});
dog.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
dog.setAlpha(200);
count ++;
mp.start();
dog.setClickable(false);
if (count==5){
fadeout();
}
}
});
giraffe.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
giraffe.setAlpha(200);
count ++;
mp.start();
giraffe.setClickable(false);
if (count==5){
fadeout();
}
}
});
spoon.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
spoon.setAlpha(200);
count ++;
mp.start();
spoon.setClickable(false);
if (count==5){
fadeout();
}
}
});
car.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
car.setAlpha(200);
count ++;
mp.start();
car.setClickable(false);
if (count==5){
fadeout();
}
}
});
}
public void fadeout(){
animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout);
animationFadeOut.setAnimationListener(this);
viewObjFades= AnimationUtils.loadAnimation(this, R.anim.trns4view_fadeout);
car.startAnimation(viewObjFades);
giraffe.setAnimation(viewObjFades);
spoon.setAnimation(viewObjFades);
dog.setAnimation(viewObjFades);
ice_cream.setAnimation(viewObjFades);
rocky_pic.startAnimation(animationFadeOut);
car.setVisibility(View.GONE);
giraffe.setVisibility(View.GONE);
spoon.setVisibility(View.GONE);
dog.setVisibility(View.GONE);
ice_cream.setVisibility(View.GONE);
rocky_pic.setVisibility(View.GONE);
}
@Override
public void onAnimationEnd(Animation animation) {
mp.release();
Log.v(TAG, "player released");
Intent end = new Intent(this, GameOver.class);
Log.v(TAG, "end object created");
end.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Log.v(TAG, "no anim");
end.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.v(TAG, "sing t");
this.startActivity(end);
Log.v(TAG, "begin game over");
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.rcky_menu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu){
if(!dog.isClickable()){
menu.removeItem(R.id.m_dog);
}
if(!spoon.isClickable()){
menu.removeItem(R.id.m_spoon);
}
if(!ice_cream.isClickable()){
menu.removeItem(R.id.m_ice_cream);
}
if(!car.isClickable()){
menu.removeItem(R.id.m_car);
}
if(!giraffe.isClickable()){
menu.removeItem(R.id.m_giraffe);
}
return true;
}
@Override
public void onBackPressed(){
}
}