我假設你有多個標題存儲。
我使用ArrayList<String>
這是比Array
更加靈活。
創建ArrayList和存儲所有標題值:
ArrayList<String> titleArr = new ArrayList<String>();
for (int i = 0; i < jArray3.length(); i++) {
news_id = Integer.parseInt((json_data.getString("news_id")));
news_title = json_data.getString("news_title");
titleArr.add(news_title);
}
2.現在把它發送到another class
,你需要顯示在單線所有的冠軍。
new AnotherClass().alistToString(titleArr);
// This line should be after the for-loop
// alistToString() is a method in another class
3.另一類結構。
public class AnotherClass{
//.................. Your code...........
StringBuilder sb = new StringBuilder();
String titleStr = new String();
public void alistToString(ArrayList<String> arr){
for (String s : arr){
sb.append(s+"\n"); // Appending each value to StrinBuilder with a space.
}
titleStr = sb.toString(); // Now here you have the TITLE STRING....ENJOY !!
}
//.................. Your code.............
}