#java #android
Вопрос:
Привет, есть ли какой-либо способ добавить SpreadsheetWebService в MainActivity, не вызывая его из другого класса? Я надеюсь, что кто-нибудь поймет, что я имею в виду.
SpreadsheetWebService.java
@POST("1FAIpQLSd9jl6cAH5h8wmwFok8xh-ECLLpXWTqUopgzmNBQM5_xt3VMw/formResponse")
@FormUrlEncoded
Call<Void> feedbackSend(
@Field("entry.1942285924") String feedback,
@Field("entry.1133595447") String name,
@Field("entry.414154651") String email
);
MainActivity.java
private void sendData() { // Send feedback to Google Spreadsheet if text input is valid
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://docs.google.com/forms/d/e/") // Your spreadsheet URL
.build();
final SpreadsheetWebService spreadsheetWebService = retrofit.create(SpreadsheetWebService.class);
String feedbackInput = feedbackInputField.getText().toString();
String nameInput = nameInputField.getText().toString();
String emailInput = emailInputField.getText().toString();
Call<Void> feedbackCall = spreadsheetWebService.feedbackSend(feedbackInput, nameInput, emailInput);
feedbackCall.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
Log.d("XXX", "Submitted. " response);
Toast.makeText(MainActivity.this,"Your feedback was submitted!",Toast.LENGTH_LONG).show();
// Clear all fields after submitting
feedbackInputField.setText("");
nameInputField.setText("");
emailInputField.setText("");
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
Log.e("XXX", "Failed", t);
Toast.makeText(MainActivity.this,"There was an error!",Toast.LENGTH_LONG).show();
}
});
}