How do or where do I define variables that can be used throughout an activity? I have three onClick Listeneners that contain a bunch of if else statements within each. One onClick causes a bunch a calaculations to occur, another onClick saves results of the calculations using out.write instructions. I am having a problem getting double variables from within if else calcuations of an onClick routine to be known to the save onClick portion of my code. I have been reading books and looking for answers but nothing seems to work. I am using a breakpoint to stop before an out.write that contains a variable from my execution onClick routine but they are unknown values. I first thought the variables need to be global but I just need them to be available throughtout the activity.
I have read plenty of books and tried to comprehend but I jumped into java and wrote 3000+ lines. Everything works as far as getting input, deciding what the inputs were, and displaying the results. I even create a nice .xml file on the sdcard showing all the data results. The problem is when I try and put a variable in the out.write code the variable m1_sqs1_eng is unknown in that onCreate routine. I had my variables defined like your example but it did not work. Some code example of my problem:
public class MyActivity extends Activity {
private EditText m1_sqs1;
private Spinner m1_sqs1_spinner;
private double m1_sqs1_eng;
private double m1_sqs1_value;
protected onCreate( Bundle savedBundle ) {
m1_sqs1_spinner = (Spinner) findViewById(R.id.m1_sqs1_spinner);
m1_sqs1 = (EditText) findViewById(R.id.m1_sqs1);
btnExecute.setOnClickListener(new View.OnClickListener() {
if (((m1_sqs1_spinner.getSelectedItem().toString().equals("in")))) {
double m1_sqs1_eng = new Double(m1_sqs1.getText().toString());
});
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
m1_sqs1_value = m1_sqs1_eng;
out.write (" <Cell ss:StyleID=\"s44\"><Data ss:Type=\"Number\">" + m1_sqs1_value + "</Data><NamedCell ss:Name=\"Print_Area\"/></Cell>\r\n");
});
}
}