Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid programming define new variable using old?
    text
    copied!<p>How can I define a new variable with an old one in java in Android? I'm talking about the part of this code that has strings <code>to, message, subject</code> and then some placeholding names to the right of the equals sign. I need to know how to change the values such as <code>textSubject</code> etc to a relevant variable previously defined. When I outright replace them, it doesnt work for some reason. </p> <p>Also, I can't figure out why it won't take the onClick method right before that. Here is the code.</p> <pre><code>public class RefillActivity extends Activity { public String name; public String birthday; public String prescriptionOptions; public String notes; public String number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.refill_activity_main); sendRefillRequest(); Button submit = (Button) findViewById(R.id.ButtonSendRefillRequest); submit.setOnClickListener(new View.onClickListener() { @Override public void onClick(View view) { String to = textTo.getText().toString(); String message = textMessage.getText().toString(); String subject = name.getText().toString(); Intent mEmail = new Intent(Intent.ACTION_SEND); mEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@example.com"}); mEmail.putExtra(Intent.EXTRA_SUBJECT, subject); mEmail.putExtra(Intent.EXTRA_TEXT, message); // prompts to choose email client mEmail.setType("message/rfc822"); startActivity(Intent.createChooser(mEmail, "Choose an email client to send your feedback!")); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.refill, menu); return true; } public void sendRefillRequest(){ final EditText nameField = (EditText) findViewById(R.id.EditTextName); name = nameField.getText().toString(); final EditText birthdayField = (EditText) findViewById(R.id.EditTextBirthday); birthday = birthdayField.getText().toString(); final EditText numberField = (EditText) findViewById(R.id.EditTextPrescriptionNumber); number = numberField.getText().toString(); final Spinner prescriptionOptions = (Spinner) findViewById(R.id.SpinnerPrescriptionOptions); this.prescriptionOptions = prescriptionOptions.getSelectedItem().toString(); final EditText notesField = (EditText) findViewById(R.id.EditTextSpecialNotes); notes = notesField.getText().toString(); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload