我如何使用外部存储将我的值保存在表单中,在排行榜中创建一个新条目,并能够提取数据?

How could I use external storage to save my values on a form, create a new entry in a leader board, and be able to pull the data back?

我对 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 以及它们应该去哪里。很抱歉就此胡说八道,因为我确信有一个简单的解决方案,但我不知道它是什么。我保存它的代码没有在上面显示,因为它太大了。

看看this official Android tutorial;这很有帮助。它展示了如何设置您的项目以向外部存储写入文件和从外部存储读取文件,以及如何设置您的文件。

然后,here's another tutorial。它显示一旦你得到你的文件,你可以像这样将它写入存储:

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();
}