2015-01-19 5 views
0

이것은 내 주요 수업입니다. 사용자 입력에서 double을받는 곳.다른 활동의 데이터 가져 오기, Android 스튜디오

public void onPayClick(View view){ 
    Intent payIntent = new Intent(this, payActivity.class); 

    final EditText amountInput = (EditText) findViewById(R.id.amountInput); 
    final EditText yearInput = (EditText) findViewById(R.id.yearInput); 
    final EditText interestInput = (EditText) findViewById(R.id.interestInput); 

    double amountDouble = Double.parseDouble(amountInput.getText().toString()); 
    double yearDouble = Double.parseDouble(yearInput.getText().toString()); 
    double interestDouble = Double.parseDouble(interestInput.getText().toString()); 

    payIntent.putExtra("amountDouble", amountDouble); 
    payIntent.putExtra("yearDouble", yearDouble); 
    payIntent.putExtra("interestDouble", interestDouble); 

    startActivity(payIntent); 
} 

이 내가 대출을 계산하고 싶습니다, 여기 내 두 번째 활동이다하지만 난 그냥 그것을하지 않는, 작동하는 경우 amountDouble보고 인쇄하려고 해요 ....

TextView printPay = (TextView) findViewById(R.id.printPay); 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_pay); 

    Bundle payData = getIntent().getExtras(); 

    if(payData == null){ 
     printPay.setText("Villa, þú verður að filla upp í alla reiti."); 
     return; 
    } 
    String amountDouble = payData.getString("amountDouble"); 
    String yearDouble = payData.getString("yearDouble"); 
    String interestDouble = payData.getString("interestDouble"); 

    String sum1 = amountDouble; 
    printPay.setText(sum1); 
} 

payButton을 클릭 할 때마다 응용 프로그램이 충돌합니다. 당신이 intent하지 bundle에서에서 해당 데이터를 가져 그래서 직접 intent에 그 값을 추가 Activity 1 일부터

+0

같은 2 Activity 변화에? –

+0

첫 줄 ..... – hjaltist

+0

onCreate에서 setContentView를 수행해야합니다. – zoki

답변

3

. 그 외에도 TextView이 클래스 상단에 있으므로 nullsetContentView(R.layout.activity_pay); 이후에 onCreate(...) 안에 정의하십시오. 당신이 두 번째 활동에서 텍스트 뷰 printPay 정의이

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_pay); 
    TextView printPay = (TextView) findViewById(R.id.printPay); 

    String amountDouble = String.valueOf(getIntent().getDoubleExtra("amountDouble", 0.0)); 
    String yearDouble = String.valueOf(getIntent().getDoubleExtra("yearDouble", 0.0); 
    String interestDouble = String.valueOf(getIntent().getDoubleExtra("interestDouble", 0.0); 

    String sum1 = amountDouble; 
    printPay.setText(sum1); 
} 

more info of getDoubleExtra(java.lang.String, double)

+0

문제는 TextView입니다. 고마워! – hjaltist

관련 문제