我想將自定義數組列表中的元素放到字符串中。但是當我試圖迭代它時,它只打印最後一個條目。這是一個todolist應用程序,該應用程序應該具有任務的名稱,根據任務是否完成,可以是1或0。將自定義數組列表的元素複製到字符串
這是迄今爲止代碼:
Entry.java
public class Entry {
String S;
boolean b;
public Entry(String S, boolean b) {
this.S = S;
this.b = b;
}
public String getS() {
return S;
}
public void setS(String S) {
this.S = S;
}
public void setB(boolean b) {
this.b = b;
}
public boolean isB() {
return b;
}
}
MainActivity.java
ArrayList<Entry> mEntries;
String copy;
String name1;
int i;
public String getShareData() {
for (Entry n : mEntries) {
name1 = n.getS();
i = boolToInt(n.isB());
copy = name1 + "\t" + i + "\n";
}
return copy;
}
public int boolToInt(boolean b) {
return b ? 1 : 0;
}
,因爲你告訴它這只是印刷中的最後一項。你想要它做什麼? – shmosel