如何从日历上的日期传递到另一个活动[Android版] [英] How to pass the date from the calendar to another activity [Android]

查看:219
本文介绍了如何从日历上的日期传递到另一个活动[Android版]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从日历传递日期另一个活动的麻烦。这并不是说我想显示当前的日期,它是用户选择的,我有codeD日历的日期。结果
下面是我的codeS。

I am having trouble with passing the date from the calendar to another activity. It's not the current date that I wanted to show, it's the date that the user selects on the calendar that I have coded.
Below are my codes.

                            @Override
                public void onClick(View view)
                {
                    String date_month_year = (String)view.getTag();
                    selectedDayMonthYearButton.setText(new StringBuilder().append("Selected:").append(date_month_year));

                    Intent k = new Intent(Calendar_Event.this, Create_Events.class);
                 startActivity(k);

                    try
                    {
                        Date parsedDate = dateFormatter.parse(date_month_year);
                        Log.d(tag, "Parsed Date: " + parsedDate.toString());
                    }
                    catch(ParseException e)
                    {
                        e.printStackTrace();
                    }
                } 


                public int getCurrentDayOfMonth()
                    {
                        return currentDayOfMonth;
                    }

                private void setCurrentDayOfMonth(int currentDayOfMonth)
                    {
                        this.currentDayOfMonth = currentDayOfMonth;
                    }
                public void setCurrentWeekDay(int currentWeekDay)
                    {
                        this.currentWeekDay = currentWeekDay;
                    }
                public int getCurrentWeekDay()
                    {
                        return currentWeekDay;
                    }

        }//end GridCellAdapter

我试图传递选定的onClick到这一类被链接到下一个活动的日期。结果任何帮助将大大AP preciated,谢谢你!

I trying to pass the date selected onClick to the next activity that this class is linked to.
Any help will be greatly appreciated, Thanks you!

推荐答案

使用 Intent.putExtra(字符串日期)从一个活动传递日期到另一个活动。更改按钮单击code作为Calendar_Event.class:

use Intent.putExtra(String date) for passing date from one activity to another Activity. Change your Button Click Code as in Calendar_Event.class:

在Calendar_Event活动:

//Create new Intent Object, and specify class
Intent intent = new Intent();

intent.setClass(Calendar_Event.this,Create_Events.class);

intent.putExtra("passdate","Date_var_here");  

Calendar_Event.this.startActivity(intent);

在Create_Events活动:

//obtain  Intent Object send  from SenderActivity
  Intent intent = this.getIntent();

  /* Obtain String from Intent  */
  if(intent !=null)
  {
     String strdata = intent.getExtras().getString("passdate");
    // DO SOMETHING HERE
  }
  else
  {
    // DO SOMETHING HERE
  }

这篇关于如何从日历上的日期传递到另一个活动[Android版]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆