我对Java还是很陌生,因为我已经使用Java不到一年了,并且不确定如何解决这个问题。
我的代码开始保存值,但是我需要它才能在列表中创建新条目。
public void setupSaveButton() {
Button save = findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculateTotal();
getTeamNumber();
getMatchNumber();
//output the total to leaderboard where it saves and ranks them
//save the data to a list in the leaderboard
}
});
}
例如,在iOS或Android上的移动记事本应用程序中,当您保存记事时,它将在菜单中创建新的视觉效果。它有您的标题和其他内容,但是我不知道如何创建XML小部件并为它们分配ID以及将它们放在何处。我对此感到很抱歉,因为我确定有一个简单的解决方案,但我不知道它是什么。我上面保存的代码没有在上面显示出来,因为它太大了。
看看这个官方的Android教程 ; 这很有帮助。它显示了如何设置项目以在外部存储中读写文件,以及如何设置文件。
然后,这是另一个教程。结果表明,一旦获得文件,就可以将其写入存储:
try {
FileOutputStream fos = new FileOutputStream(myExternalFile);
fos.write(yourValuesAsString.getBytes()); // Convert any values you want to store into strings before writing to files
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
然后像这样从存储中读取它:
try {
FileInputStream fis = new FileInputStream(myExternalFile);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
myData = myData + strLine;
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句