如何将用户输入保存在内部存储中(Android Studio)

时间:2019-04-02 18:00:03

标签: java android file save

我不确定它是否保存输入我的代码是否保存用户输入但不加载文件

我猜写按钮可以在listView中显示用户输入,但是我找不到文件名

void paintEvent(QPaintEvent* event)
    {
        QString text = "Short text";
        text = text.repeated(1000); // Check with a very long text
        QPainterPath rawPath;
        rawPath.addEllipse(QRect(0, 0, 200, 200));

        QPainterPath path;

        double const step = 1.0 / double(text.length());
        double percent = 0.0;
        for(QChar const& c: text)
        {
            double angle = rawPath.angleAtPercent(percent);
            QPointF point = rawPath.pointAtPercent(percent);

            QTransform mat;
            mat.rotate(-angle);
            QPainterPath p2;
            p2.addText(0, 0, font(), c);
            p2 = mat.map(p2);
            path.addPath(p2.translated(point));
            percent += step;
        }

        QPainter painter(this);
        painter.drawPath(path.translated(100, 100));
    }

读取按钮根本不起作用,我看不到问题

        btnwrite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String msg = editText.getText().toString();
                if (addArray.contains(msg)) {
                    Toast.makeText(getBaseContext(), "Enter Sth", Toast.LENGTH_SHORT).show();
                }
                try {
                    FileOutputStream Fops = openFileOutput(filename,Context.MODE_PRIVATE);
                    Fops.write(msg.getBytes());
                    Fops.close();
                    Toast.makeText(getBaseContext(), "Saved", Toast.LENGTH_SHORT).show();
                    addArray.add(msg);
                    ArrayAdapter <String> adapter = new ArrayAdapter <String>(Activity_ToDoList.this, android.R.layout.simple_list_item_1, addArray);
                    show.setAdapter(adapter);
                    ((EditText) findViewById(R.id.editText)).setText("");

                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });

}

0 个答案:

没有答案