Reputation: 111
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.
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.
Upvotes: 0
Views: 93
Reputation: 226
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
}
Upvotes: 1
Reputation: 3282
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.
Upvotes: 1
Reputation: 1502
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.
Upvotes: 1