转换为String后,TextView返回java代码

时间:2015-01-10 14:50:48

标签: java android random textview numbers

我正在尝试从随机数字中获取一个字符串,并且它正在返回

Nome1:com.example.OtherActivity@3c9413b0 x com.example.OtherActivity@132c3229:Nome2

Nome1和Nome2转换良好,但其余的不是

我的OtherActivity类就是这个

public class OtherActivity{


private String teamOne;


public Team(String teamOne) {
    this.teamOne = teamOne;

}


public String getTeamOne() {
    return teamOne;
}

public void setTeamOne(String teamOne) {
    this.teamOne = teamOne;
}




}

我的TeamMixer类

public class TeamMixer extends PlayerNames {

public ArrayList<Team> times = null;

public TeamMixer(ArrayList<Team> times) {
    this.times = times;
}

protected String tellJoke(){
    Double randomNumber = new Double(Math.random() * times.size());
    Double randomNumber1 = new Double(Math.random() * times.size());
    int randomNum1 = randomNumber1.intValue();
    int randomNum = randomNumber.intValue();
    Team time2 = times.get(randomNum);
    Team time3 = times.get(randomNum1);
    String timeString = String.valueOf(time3);
    String timeString2 = time2.toString();
    if(time2 == time3){
        Double randomNumber2 = new Double(Math.random() * times.size());
        int randomNum2 = randomNumber2.intValue();
        Team time4 = times.get(randomNum2);
        String timeString3 = String.valueOf(time4);
        String tentativa = sayTeam(timeString2, timeString3);

        return tentativa;
    } else{
        String tentativa2 = sayTeam(timeString, timeString2);
        return tentativa2;
    }


}


protected String sayTeam(String teams, String teams2){

    String message = (getNamePlayerOne()+": " + teams + " x " + teams2 + " :" + getNamePlayerTwo());
    return message;
}

}

感谢帮助!

1 个答案:

答案 0 :(得分:2)

重写您的Team类toString方法,因此返回的字符串不是Team对象:

private class Team {
    String str;

    public Team(String str) {
        this.str = str;
    }

    @Override
    public String toString() {
        return str;
    }
}