2017-07-15 30 views
0

我一直在努力收集信息,然後以電子郵件的形式發送它。我的所有其他EditTexts除了第一個,飛行員(提示是名字,如飛行員的名字)的例外。我已經完成了多個小時,但我似乎無法找到問題所在。我知道它的空的唯一原因是因爲當它進入電子郵件格式的所有它說的是空我的EditText不斷出現爲空

public class InfoSheet extends AppCompatActivity { 
private double VesselUnits; 
private EditText pilot, ship, to, from, LOA, MBDTH, CUSD, zone1, zone2, CallSign; 
private Spinner agent_spinner; 
private Button btnSubmit; 
private String date, agent, Spilot, Sship, Sto, Sfrom, Szone1, Szone2, SCallSign, SVesselUnits; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_info_sheet); 
    date=getTodaysDate(); 
    addListenerOnButton(); 
} 
public void collectNCalc(){ 
    //grab all of our info 
    agent_spinner = (Spinner) findViewById(R.id.agent_spinner); 
    btnSubmit = (Button) findViewById(R.id.btnSubmit); 
    pilot = (EditText) findViewById(R.id.Pilot); 
    ship = (EditText) findViewById(R.id.ship); 
    to = (EditText) findViewById(R.id.to); 
    from = (EditText) findViewById(R.id.from); 
    LOA = (EditText) findViewById(R.id.LOA); 
    MBDTH = (EditText) findViewById(R.id.MBDTH); 
    CUSD = (EditText) findViewById(R.id.CUSD); 
    zone1 = (EditText) findViewById(R.id.zone1); 
    zone2 = (EditText) findViewById(R.id.zone2); 
    CallSign = (EditText) findViewById(R.id.CallSign); 

    //convert what we need to int to do equations 
    String sLOA = LOA.getText().toString(); 
    double intLOA = Integer.valueOf(sLOA); 
    intLOA = intLOA*3.281; 

    String sMBDTH = MBDTH.getText().toString(); 
    double intMBDTH = Integer.valueOf(sMBDTH); 
    intMBDTH = intMBDTH*3.281; 

    String sCUSD = CUSD.getText().toString(); 
    double intCUSD = Integer.valueOf(sCUSD); 
    intCUSD = intCUSD*3.281; 

    VesselUnits = intLOA*intMBDTH*intCUSD; 
    VesselUnits = VesselUnits/10000; 
    Spilot=pilot.getText().toString(); 
    Sship=ship.getText().toString(); 
    Sto=to.getText().toString(); 
    Sfrom=from.getText().toString(); 
    Szone1=zone1.getText().toString(); 
    Szone2=zone2.getText().toString(); 
    SCallSign=CallSign.getText().toString(); 
    agent=agent_spinner.getSelectedItem().toString(); 
    //SVesselUnits=String.valueOf(VesselUnits); 
} 
public void addListenerOnButton() { 
    final Context context2 = this; 
    btnSubmit = (Button) findViewById(R.id.btnSubmit); 
    btnSubmit.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent i2 = new Intent(context2, DigitalSignature.class); 
      //do the Calc 
      collectNCalc(); 
      //pass to next activity 
      i2.putExtra("Pilot",Spilot); 
      i2.putExtra("ship",Sship); 
      i2.putExtra("to",Sto); 
      i2.putExtra("from",Sfrom); 
      i2.putExtra("zone1",Szone1); 
      i2.putExtra("zone2",Szone2); 
      i2.putExtra("callsign",SCallSign); 
      i2.putExtra("agent",agent); 
      i2.putExtra("vessleunits",VesselUnits); 
      i2.putExtra("date",date); 
      startActivity(i2); 
     } 

    }); 
} 

其發送到下一個和最後一個活動:

public class DigitalSignature extends AppCompatActivity { 
String pilot, ship, to, from, zone1, zone2, CallSign, agent, date; 
Toolbar toolbar; 
Button btn_get_sign, mClear, mGetSign, mCancel, btn_send; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_digital_signature); 
    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     pilot = extras.getString("pilot"); 
     ship = extras.getString("ship"); 
     to = extras.getString("to"); 
     from = extras.getString("from"); 
     zone1 = extras.getString("zone1"); 
     zone2 = extras.getString("zone2"); 
     CallSign = extras.getString("callsign"); 
     agent = extras.getString("agent"); 
     vesselUnit = extras.getDouble("vesselunits"); 
     date = extras.getString("date"); 
    } 
btn_send.setOnClickListener(new OnClickListener() { 
     public void onClick(View v){ 
      Uri path = Uri.parse("file://" + file); 
      Intent emailIntent = new Intent(Intent.ACTION_SEND); 
      emailIntent.putExtra(Intent.EXTRA_TEXT, pilot+"\n"+ship+"\n"+to+"\n"+from+"\n"+zone1+"\n"+zone2+"\n"+CallSign+"\n"+agent+"\n"+vesselUnit); 
      // set the type to 'email' 
      emailIntent.setType("image/png"); 
      String to[] = {"[email protected]"}; 
      emailIntent.putExtra(Intent.EXTRA_EMAIL, to); 
      // the attachment 
      emailIntent.putExtra(Intent.EXTRA_STREAM, path); 
      // the mail subject 
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, pilot+"'s Ticket for "+ship); 
      startActivity(Intent.createChooser(emailIntent , "Send email...")); 
     } 
    }); 
} 

我留下了很多的與我的問題無關的其他代碼,但如果任何人都可以指出我爲什麼變得空白,那麼您將成爲救星!

回答

2

您需要使用extras.getString("Pilot");

與其使用extras.getString("pilot");