0

I'm coming with an unusual question, I think. I made a program which calculate the difference between two dates in java, and I want to make an android application with this program.

This is what I did until now: enter image description here

enter image description here

I'm begginer in Android development and my question is how I can do the connection between the algorithm and the application. I know that when the user will push the button "calculate" an event is triggered and the result should be displayed on the screen. I don't know how to make the connection between algorithm and the design part of the application.

2
  • You should look into date representations in Android, see which one fits best, see how to convert it to the desired form that your algorithm receives and finally convert it to a string in order to display it on the screen. Commented Jun 25, 2016 at 21:30
  • Select the correct answer and mark it according to the rules of the site. Commented Jun 25, 2016 at 21:56

3 Answers 3

1

In MainActivity make private variable

private Button calculateBtn;
private EditText startDate;
private EditText endDate;
private TextView result;

in OnCreate():

calculateBtn = (Button) findViewById(R.id.**[youIdButton]**);
startDate = (EditText) findViewById(R.id.**[endDate]**);
endDate = (EditText) findViewById(R.id.**[endDate]**);
result = () findViewById(R.id.**[result]**);

calculate.setOnClickListener(new OnClickListener(){

       result.setText(calculate(startDate.getText().toString(), endDate.getText().toString()));
});

in MainActivity class make method

private String calculate(String startDate, String endDate)){
     //calc
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can make a java function with it like

public String CalculateTime(String startDate, String endDate)
{

    //convert

    //calculate

    //convert result

    //return statement


}

Call this function from the button onClick event, get the result and then set the TextView text value.

Comments

1

You should instantiate you algorithm's class in Activity. find your button and set click listener, in which algorithm will be triggered. Create EditText references in your activity and bind thise to text fields.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.