当我从DatePicker中选择日期时,我想开始另一个日期 活动(GetAttendance),但它需要我两次,我想要一次。是否可以打电话一次?
//代码
classes.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
showDialog(DATE_DIALOG_ID);
} catch (Exception e)
{
e.printStackTrace();
}
}
});
protected Dialog onCreateDialog(int id)
{
switch (id) {
case DATE_DIALOG_ID: // set date picker as current date
return new DatePickerDialog(this, obj,year, month,day);
}
return null;
};
DatePickerDialog.OnDateSetListener obj=new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth)
{
try
{ dday=dayOfMonth;
mmonth=monthOfYear;
yyear=year;
getDateString=parseDateMethod(dday,mmonth,yyear);
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
pd=ProgressDialog.show(Home.this, "passing List", "Processing");
new AttendanceAthnticate().execute();
}
//Toast.makeText(Home.this,"Date is "+getDateString, Toast.LENGTH_LONG).show();
}
};
// AsynTask:
private class AttendanceAthnticate extends AsyncTask<String, Void, ArrayList<SetAttendance>>
{
ArrayList<SetAttendance> listAtt;
@Override
protected ArrayList<SetAttendance> doInBackground(String... params)
{
listAtt=new AllMethods().getAttendance();
pd.cancel();
return listAtt;
}
@Override
protected void onPostExecute(ArrayList<SetAttendance> result)
{
try
{
if(result.size()>0)
{
Intent iii=new Intent(Home.this,GetAttendance.class);//It takes me two time which i want for one time
iii.putExtra("shahid", result);
startActivity(iii);
}
else
{
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
在issue之后,似乎DatePickerDialog.OnDateSetListener()
在设置日期时被调用了两次。所以你有这个错误是正常的。
可能的解决方案是:
DatePickerDialog.OnDateSetListener obj=new DatePickerDialog.OnDateSetListener()
{
boolean alreadyFired = false;
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth)
{
if (alreadyFired == false)
{
try
{ dday=dayOfMonth;
mmonth=monthOfYear;
yyear=year;
getDateString=parseDateMethod(dday,mmonth,yyear);
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
pd=ProgressDialog.show(Home.this, "passing List", "Processing");
new AttendanceAthnticate().execute();
}
//Toast.makeText(Home.this,"Date is "+getDateString, Toast.LENGTH_LONG).show();
alreadyFired = true;
}
else
{
alreadyFired = false;
}
}
};