0
我有一些結果,我將它們存儲在ArrayList中。我想將這些txt文件保存(輸出)到我的SD卡上。但我不知道。我嘗試一個代碼,但文件不是。如果文件被創建,我會寫入下一個活動。我想知道如何將我的ArrayList寫入下一個Activity。如何寫入我的ArrayList的txt文件?
分:列表,存儲谷歌地圖標記位置 szoveg:一個字符串ArrayList。
if(points.size()>1 ) {
for(int i=0;i<points.size();i++){
for(int j=i+1;j<points.size();j++){
Location LocA = new Location("A");
LocA.setLatitude(points.get(i).latitude);
LocA.setLongitude(points.get(i).longitude);
Location LocB= new Location("B");
LocB.setLatitude(points.get(j).latitude);
LocB.setLongitude(points.get(j).longitude);
double distance = LocA.distanceTo(LocB);
String rad = "";
rad=sharedPreferences.getString("rad"+i, "0");
double radius=Double.parseDouble(rad);
String rad2 = "";
rad2=sharedPreferences.getString("rad"+j, "0");
double radius2=Double.parseDouble(rad2);
if(distance<radius && distance < radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
else if (distance>radius && distance<radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " + (j+1) + " -> " + (i+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
else if (distance<radius && distance>radius2)
{
szoveg.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
Toast.makeText(getBaseContext(), "Kommunikál: " +(i+1)+ " -> " +(j+1)+ " - " + distance + " m" , Toast.LENGTH_SHORT).show();
// Drawing Polyline on the map
//drawPolyline(point);
}
//else Toast.makeText(getBaseContext(), "Nem kommunikál - " + distance + " m" , Toast.LENGTH_SHORT).show();
}
}
}
else Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();
}
我嘗試另一個應用程序這一點,但不工作(我用的onCreate writeTest()):
@SuppressLint("SdCardPath")
private void writeTest() {
lista = new ArrayList<String>();
int i= 0;
int j=0;
int distance = 100;
lista.add(("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m"));
lista.add("Kommunikál: " +(i+1)+ " -> " +(j+1)+ " && " +(j+1)+ " -> " +(i+1)+ " - " + distance + " m");
try {
FileOutputStream fileOut = new FileOutputStream("/mnt/sdcard/elso.txt");
ObjectOutputStream oos = new ObjectOutputStream (fileOut);
oos.writeObject(lista);
fileOut.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
你可以隔離你的問題,只發布相關的代碼,而不是張貼那麼長的代碼。 –