嗯,我试图传递一个使用getDate()方法从日历视图中提取的长并将其设置为long并传递它...它适用于一个按钮我在同一界面中有多个按钮并且用于第一个按钮它工作正常但是为了发送一个我有和发出数据没有被传递:S
//THis one passes the long without any issues
Create = (Button) findViewById(R.id.CreateApp);
Create.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
finish();
long date = Present.getDate();
Intent Crea = new Intent(getApplicationContext(),CreateAppointment.class);
Crea.putExtra("SelectedDate", date);
startActivity(Crea);
}
});
//在另一个班级接收时的代码
Intent g = getIntent();
final long SDate = g.getLongExtra("SelectedDate", 0);
//THE PROBLEM ONE :S
Edit = (Button) findViewById(R.id.VEditApp);
Edit.setOnClickListener(new OnClickListener() {
public void onClick(View arViewg0) {
finish();
long date = Present.getDate();
Intent EDT = new Intent(getApplicationContext(),viewedit.class);
EDT.putExtra("EDTDate", date);
startActivity(EDT);
}
});
//我用什么来接收其他课程
Intent EditRecieve = new Intent();
long Cur_Date = EditRecieve.getLongExtra("EDTDate", 2);
有人能告诉我为什么我没有得到这个值以及为什么默认值会被传递?
答案 0 :(得分:0)
尝试这种方式在您调用新活动后完成您的活动:::::
//THis one passes the long without any issues
Create = (Button) findViewById(R.id.CreateApp);
Create.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
long date = Present.getDate();
Intent Crea = new Intent(getApplicationContext(),CreateAppointment.class);
Crea.putExtra("SelectedDate", date);
startActivity(Crea);
finish();
}
});
/代码在另一个班级收到时
Intent g = getIntent();
final long SDate = g.getLongExtra("SelectedDate", 0);
//THE PROBLEM ONE :S
Edit = (Button) findViewById(R.id.VEditApp);
Edit.setOnClickListener(new OnClickListener() {
public void onClick(View arViewg0) {
Intent EDT = new Intent(getApplicationContext(),viewedit.class);
EDT.putExtra("EDTDate", SDate );
startActivity(EDT);
finish();
}
});
//我用什么来接收其他课程
Intent EditRecieve = new Intent();
long Cur_Date = EditRecieve.getLongExtra("EDTDate", 2);
答案 1 :(得分:0)
在不起作用的示例中,您写道:
Intent EditRecieve = new Intent();
long Cur_Date = EditRecieve.getLongExtra("EDTDate", 2);
但在你写的第一个例子中,你写道:
Intent g = getIntent();
final long SDate = g.getLongExtra("SelectedDate", 0);
所以看起来像一个简单的拼写错误,用“getIntent()”替换“new Intent()”,你应该很好。