2015-01-10 61 views
0

我試圖得到一個串出一個隨機數,並且它返回這個的TextView轉換爲字符串

Nome1回​​國後的Java代碼:[email protected] X [email protected]: 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; 
} 

} 

感謝幫助!

回答

2

覆蓋您Team類toString方法,所以它返回字符串不是團隊對象:

private class Team { 
    String str; 

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

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

尼斯!謝謝您的幫助!工作很好。 – androidai