lundi 30 octobre 2017

setText() not working in my code

I am making a app. When I try to setText on my TextView it does not work!

scoreteam_a and scoreteam_b does not setText(). The if statements do not work too. please help me. What's wrong in my code? teama and teamb setText() method works but not on scoreteam_a and scoreteam_b. I directly acces varibales from activiy in the methods.

Here's my code :

     package com.example.android.courtcounter;

     import android.content.Intent;
     import android.os.Bundle;
     import android.support.v7.app.AppCompatActivity;
     import android.view.View;
     import android.view.animation.AlphaAnimation;
     import android.view.animation.Animation;
     import android.widget.TextView;

     public class FinishActivity extends AppCompatActivity {
       Bundle bundle;
       String teama_name;
       String teamb_name;
       int scoreteama;
       int scoreteamb;
String scoreTeamAString;
String scoreTeamBString;
private TextView winnera;
private TextView winnerb;
private TextView draw;
private TextView teama;
private TextView teamb;
private TextView scoreteam_a;
private TextView scoreteam_b;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_finish);



    bundle = getIntent().getExtras();

    winnera = (TextView) findViewById(R.id.winnera);
    winnerb = (TextView) findViewById(R.id.winnerb);
    draw = (TextView) findViewById(R.id.draw);
    teama = (TextView) findViewById(R.id.teama);
    teamb = (TextView) findViewById(R.id.teamb);
    scoreteam_a = (TextView) findViewById(R.id.scoreteama);
    scoreteam_b = (TextView) findViewById(R.id.scoreteamb);

    teama_name = MainActivity.teamAName;
    teamb_name = MainActivity.teamBName;
    scoreteama = ScoringActivity.scoreTeamA;
    scoreteamb = ScoringActivity.scoreTeamB;
    scoreTeamAString = ScoringActivity.stringTeamA;
    scoreTeamBString = ScoringActivity.stringTeamB;

    Animation anim = new AlphaAnimation(0.0f, 1.0f);
    anim.setDuration(50); //You can manage the blinking time with this parameter
    anim.setStartOffset(20);
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(Animation.INFINITE);

    if (scoreteama > scoreteamb) {
        winnera.setVisibility(View.VISIBLE);
        winnera.startAnimation(anim);
    } else if (scoreteamb > scoreteama) {
        winnerb.setVisibility(View.VISIBLE);
        winnerb.startAnimation(anim);
    } else if (scoreteamb == scoreteama) {
        draw.setVisibility(View.VISIBLE);
        draw.startAnimation(anim);
    }

    teama.setText(teama_name);
    teamb.setText(teamb_name);
    scoreteam_a.setText(ScoringActivity.stringTeamA);
    scoreteam_b.setText(ScoringActivity.stringTeamB);



    TextView shareButton = (TextView) findViewById(R.id.share);
    shareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, teama_name + " vs " + teamb_name + "\n" + teama_name + " = " + scoreteama + "\n" + teamb_name + " = " + scoreteamb);
            startActivity(shareIntent);
        }
    });
}

public void newmatch(View v) {
    Intent intent = new Intent(FinishActivity.this, MainActivity.class);
    startActivity(intent);
    winnera.setVisibility(View.INVISIBLE);
    winnerb.setVisibility(View.INVISIBLE);
    draw.setVisibility(View.INVISIBLE);
    winnera.clearAnimation();
    winnerb.clearAnimation();
    draw.clearAnimation();
   }
   }

Aucun commentaire:

Enregistrer un commentaire