我正在創建一個應用程序,我必須一遍又一遍地引用相同的數據。我是新來的編碼,所以我不知道我是否正確地做了。現在我用setter和getters來創建一個類來存儲我想要的數據。保存ArrayList項目
(Item類)
public class PlayerList {
private String score;
private String team;
private String name;
private String scoreWeek;
private String position;
private String goals;
private String assists;
private String yellowCards;
private String redCards;
private int iconID;
public PlayerList(String name, String team, String score, String scoreWeek, String position,
String goals, String assists, String yellowCards, String redCards, int iconID){
super();
this.score= score;
this.team = team;
this.name = name;
this.scoreWeek = scoreWeek;
this.position= position;
this.goals = goals;
this.assists = assists;
this.yellowCards = yellowCards;
this.redCards = redCards;
this.iconID= iconID;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getScoreWeek() {
return scoreWeek;
}
public void setScoreWeek(String scoreWeek) {
this.scoreWeek = scoreWeek;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getGoals() {
return goals;
}
public void setGoals(String goals) {
this.goals = goals;
}
public String getAssists() {
return assists;
}
public void setAssists(String assists) {
this.assists = assists;
}
public String getYellowCards() {
return yellowCards;
}
public void setYellowCards(String yellowCards) {
this.yellowCards = yellowCards;
}
public String getRedCards() {
return redCards;
}
public void setRedCards(String redCards) {
this.redCards = redCards;
}
public int getIconID() {
return iconID;
}
public void setIconID(int iconID) {
this.iconID = iconID;
}
}
然後,我提出在該數據被編輯,並把成陣列另一個類。
(編輯碼)
public class Players extends Activity {
private ArrayList<PlayerList> stateList = new ArrayList<PlayerList>();
public Players(){
PlayerList _states = new PlayerList("Name","Team","Score","Score Week", "Position",
"Goals", "Assists","Yellow Cards","Red Cards", R.drawable.client_icon);
stateList.add(_states);
PlayerList _states1 = new PlayerList("Name2","Team","Score","Score Week", "Position",
"Goals", "Assists","Yellow Cards","Red Cards", R.drawable.client_icon);
stateList.add(_states1);
PlayerList _states2 = new PlayerList("Name3","Team","Score","Score Week", "Position",
"Goals", "Assists","Yellow Cards","Red Cards", R.drawable.client_icon);
stateList.add(_states2);
}
}
編輯數據並將其添加到一個單獨的數組列表後,如何可以參考回數據。例如在應用程序的其他部分,我需要參考玩家的分數?我想將數據保存在SharedPreferences中,但它只保存集合。請幫忙。我想把它發送到另一個活動。例如,我希望它在主屏幕上顯示玩家分數。以及在一個談論球隊球員的屏幕上。
你的意思是與應用程序的另一部分?例如,您的問題是否將數據發送給其他活動? – armandooj