Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用弹出式日历在其他活动中显示选定日期_Android_Android Activity_Calendar - Fatal编程技术网

Android 使用弹出式日历在其他活动中显示选定日期

Android 使用弹出式日历在其他活动中显示选定日期,android,android-activity,calendar,Android,Android Activity,Calendar,我想在另一个活动中显示从日历中选择的日期,请帮助我,现在在我的应用程序中,它显示当前日期,但我不知道如何执行此操作。我在我的应用程序中使用简单的弹出式日历。下面是我的代码 sharedpreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE); Bundle b = getIntent().getExtras(); txt_date = (TextView) findViewById(R.id.Dat

我想在另一个活动中显示从日历中选择的日期,请帮助我,现在在我的应用程序中,它显示当前日期,但我不知道如何执行此操作。我在我的应用程序中使用简单的弹出式日历。下面是我的代码

    sharedpreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE);

    Bundle b = getIntent().getExtras();

    txt_date = (TextView) findViewById(R.id.Date_Value);
    txt_week = (TextView) findViewById(R.id.Week_Value);
    txt_baby = (TextView) findViewById(R.id.Baby_Value);
    txt_mother = (TextView) findViewById(R.id.Mother_Value);
    txt_tremester = (TextView) findViewById(R.id.Tremester_Value);

    txt_baby.setText(b.getCharSequence("baby_name"));
    txt_mother.setText(b.getCharSequence("mother_name"));
    txt_tremester.setText(b.getCharSequence("tremester"));

    img_week = (ImageView) findViewById(R.id.image_week);
    img_slide = (ImageView) findViewById(R.id.image_slide);
    img_BMI = (ImageView) findViewById(R.id.image_BMI);
    img_setting = (ImageView) findViewById(R.id.image_setting);

    String dob = sharedpreferences.getString("dob", null);

    Calendar c = Calendar.getInstance();
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH);
    day = c.get(Calendar.DAY_OF_MONTH);



    txt_date.setText(new StringBuilder()
            // Month is 0 based, just add 1
            .append(year).append("-").append(month + 1).append("-").append(day));

    String current_dob = txt_date.getText().toString();

    StringTokenizer current_tokens = new StringTokenizer(current_dob, "-");
    current_year = current_tokens.nextToken();
    current_month = current_tokens.nextToken();
    current_date = current_tokens.nextToken();

    System.out.println("year==>" + Integer.parseInt(current_year));
    System.out.println("month==>" + Integer.parseInt(current_month));
    System.out.println("date==>" + Integer.parseInt(current_date));

    StringTokenizer tokens = new StringTokenizer(dob, "-");
    selected_year = tokens.nextToken();
    selected_month = tokens.nextToken();
    selected_date = tokens.nextToken();

    System.out.println("year==>" + Integer.parseInt(selected_year));
    System.out.println("month==>" + Integer.parseInt(selected_month));
    System.out.println("date==>" + Integer.parseInt(selected_date));

使用日历视图并按如下方式设置所选日期:

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);

long milliTime = calendar.getTimeInMillis(); 

mCalendarView.setDate (milliTime, true, true);