I have two activities.
Home activity contain a list view with two buttons named checkIn and directions.when checkIn button is clicked it does some operation (say A).
When direction button is clicked it launches directions activity.So in directions activity if some condition satisfies there comes an alertbox asking for whether to check In or not.If yes is clicked,I want to do operation A on the checkin button but without destroying directions activity.ie,I want to control the button OnclickListener with the status of an alertbox in other activity without losing the state of present activity.
this is the portion of the code in getView of Listadapter used by Listview of Home activity.btnChild1 is the CheckIn button.
btnChild1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (btnChild1.getText().toString().equals("Check In")) {
btnChild1.setText("Cancel");
taskSubList.get(position).setCheckIn(1);
startTime = System.currentTimeMillis();
} else {
btnChild1.setText("Check In");
taskSubList.get(position).setCheckIn(0);
long difference =taskSubList.get(position).getTimeSpent() +System.currentTimeMillis() - startTime;
taskSubList.get(position).setTimeSpent(difference);
String values[]={Integer.toString(taskSubList.get(position).getId()), Integer.toString((int) difference)};
String updateTime=Helper.getfromUrl(updateTimeUrl,values);
if (!updateTime.equals("success"))
{
Toast.makeText(context, "Not updated", Toast.LENGTH_SHORT).show();
}
Intent reasonIn = new Intent(context.getApplicationContext(), Reason.class);
context.startActivity(reasonIn);
}
}
});
And in Directions.java
if((int)distance/1000 <= 30 && checkInStatus == 0)
{
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage("Do you want to Check In?");
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// I have to do the above function
}
});
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
alertbox.show();
}