Java 我如何使用外部存储将我的值保存在表单上,在领导板中创建新条目,并能够将数据拉回来?

Java 我如何使用外部存储将我的值保存在表单上,在领导板中创建新条目,并能够将数据拉回来?,java,android-external-storage,Java,Android External Storage,我对Java相当陌生,因为我已经使用它不到一年了,不知道该怎么做 我有开始保存值的代码,但我需要它在列表中创建一个新条目 public void setupSaveButton() { Button save = findViewById(R.id.save); save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {

我对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以及它们应该去哪里。我很抱歉在这里漫无边际,因为我相信有一个简单的解决方案,但我不知道它是什么。上面没有我保存它的代码,因为它太大了。

看看;这很有帮助。它显示了如何设置项目以在外部存储中写入和读取文件,以及如何设置文件

然后。它表明,一旦您获得了文件,您就可以像这样将其写入存储器:

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();
}
从存储器中读取,如下所示:

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

谢谢,我会将此应用到我的代码中,但我仍然不知道在按下save时如何创建xml对象;2个或3个文本视图和一个按钮使用内部存储是否比使用外部存储更好?嗯,我最近一直在使用内部存储,它很容易实现。就我个人而言,我还没有使用外部存储,但基本上是一样的,只是需要更多的检查,看看设备是否包含外部存储。部分原因是,主要是在按下save时为我的xml文件创建对象。