在androidstudio中使用共享首选项保存列表视图

w6lpcovy  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(162)

我有edittext,倒计时,列表视图,我的项目上的共享首选项。我的应用程序可以工作。我的倒计时计时器在完成我添加文本我的列表视图。我用共享的偏好保存这个。如果我打开新的倒计时计时器后,完成它添加新的文本到listview,但它只保存最后一个文本怎么可能ı 保存完整列表视图。
波莫多罗.java

public class pomodoro extends AppCompatActivity {
    Button baslat,backhome,bitir;
        EditText edittextcalisma,edittextmola;
        CountDownTimer calisma,mola;
        ArrayList<String> list = new ArrayList<String>();
        ArrayAdapter arrayAdapter;
        ListView listView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pomodoro);
             LoadPreferences();

            listView=(ListView)findViewById(R.id.listv);
            arrayAdapter = new ArrayAdapter<String>(
                    this,R.layout.list_view,R.id.textitem, list);
            listView.setAdapter(arrayAdapter);
            bitir=findViewById(R.id.bitirbutton);
            baslat = findViewById(R.id.baslatbutton);
            edittextcalisma = findViewById(R.id.edittextcalisma);
            edittextmola = findViewById(R.id.edittextmola);

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

                    closeKeyboard();

                    final int molapo = Integer.valueOf(edittextmola.getText().toString());
                    final int calismapo = Integer.valueOf(edittextcalisma.getText().toString());

                    if (calismapo <= 600 && molapo <= 600 && calismapo > 0 && molapo>0){

                        calisma = new CountDownTimer(calismapo * 60000, 1000) {
                            @Override
                            public void onTick(long millis) {

                            }
                            @Override
                            public void onFinish() {

                                final int molapo = Integer.valueOf(edittextmola.getText().toString());
                  mola = new CountDownTimer(molapo * 60000, 1000) {
                                    @Override
                                    public void onTick(long millis) {

                                    }
                                    @Override
                                    public void onFinish() {

                                        pomodoro.setText("Bitti");

                                        CountDownTimer bekle = new CountDownTimer(5000, 1000) {
                                            @Override
                                            public void onTick(long millis) {

                                            }
                                            @Override
                                            public void onFinish() {

                                                Calendar c = Calendar.getInstance();
                                                SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMMM-yyyy HH:mm");
                                                String datetime = dateformat.format(c.getTime());

                                                list.add("Çalışma Süresi : " + calismapo +"  dk  "+"\n"+  "Mola Süresi : " + molapo+"  dk  " +"\n" + datetime);
                                                arrayAdapter.notifyDataSetChanged();                                                                                                          SavePreferences("LISTS", task);

                                            }
                                        }.start();
                                    }
                                }.start();
                            }
                        }.start();
                    }
                }
            });
        }                                                                                                                                                                                                                  protected void SavePreferences(String key, String value) {

        SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = data.edit();
        editor.putString(key, value);
        editor.commit();

    }

    protected void LoadPreferences(){
        SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(this);
        String dataSet = data.getString("LISTS", "");

        list.add(dataSet);
        arrayAdapter.notifyDataSetChanged();

    }
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题