如何将CalendarText保存到CalendarView中的某一天

时间:2017-09-24 12:51:00

标签: java android android-sharedpreferences calendarview

我正在为我以前的学校制作应用程序,要求我这样做的人希望在应用程序中有一个日历,学生可以写下他们的作业。 我有Calendarview工作,但我找不到一种方法来保存我在EditText小部件中写的文本,以保存到日历中的特定日期。 有没有人知道如何做到这一点或知道可以帮助我的网站,视频或教程

这是我的代码:

package com.jmld.apps.aeresmavo;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.CalendarView;
import android.widget.EditText;

import static android.R.attr.tag;
import static com.jmld.apps.aeresmavo.R.id.calendarView;

class CalendarActivity extends AppCompatActivity {

private static final String TAG = "CalendarActivity";

private CalendarView mCalendarView;
private EditText Homework;
private SharedPreferences SaveHomework;


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

    Homework = (EditText) findViewById(R.id.homework);
    SaveHomework = getSharedPreferences("notes", MODE_PRIVATE);
    Homework.setText(SaveHomework.getString("tag", "Default Value")); //add this line
    mCalendarView = (CalendarView) findViewById(calendarView);

    mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener()

    {
        @Override
        public void onSelectedDayChange(CalendarView calendarView, int i, int i1, int i2) {
            String date = (i1 + 1) + "/" + i2 + "/" + i;   // i= year i1 = month i2 = day
            Log.d(TAG, "onSelectedDayChange: mm/dd/yyyy ");

            /** Intent intent = new Intent(CalendarActivity.this, Calendar.class);
            intent.putExtra("date", date);
            startActivity(intent); */
        }
    });
}

private void makeTag(String tag) {
    String or = SaveHomework.getString(tag, null);
    SharedPreferences.Editor preferencesEditor = SaveHomework.edit();
    preferencesEditor.putString("tag", tag); //change this line to this
    preferencesEditor.commit();
    makeTag(Homework.getText().toString());
   // ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(Homework.getWindowToken(), 0);
}

}

0 个答案:

没有答案