2011-04-29 9 views
2

버튼을 클릭하면 다른 활동에서 계산의 세부 정보를 표시하려고합니다. 어떻게 이것을 달성하십시오. 첫 활동 자바 코드가Android 인 텐트 문제

public void onClick(View v) 
{ 
    if(v.getId()==R.id.Button07) 
    { 
     Intent intent=new Intent(AdvancedCalculator.this,calculatedData.class); 
     startActivity(intent); 
    } 

는 내가 원하는 계산은 내가 제출 버튼을 누르면

String a,b; 
Integer vis; 
a = txtbox3.getText().toString(); 
b = textview1.getText().toString(); 
vis = (Integer.parseInt(a)*Integer.parseInt(b))/100; 
tv.setText(vis.toString()); 

난 결과 'TV를'원하는이 다음 활동에 표시하는 것입니다. 하지 OnCreate, 두 번째 활동에서

public void onClick(View v) { 

    //Put your calculation code here 

    Bundle b = new Bundle(); 
    b.putString("answer", youranswer); 
    //You could also use putInteger, whichever you prefer. 

    Intent intent=new Intent(AdvancedCalculator.this,calculatedData.class);  
    intent.putExtras(b); 
    startActivity(intent); 


} 

: 나는 어떤 도움이 감사

첫 번째 활동에서

답변

1

감사 크게되어

추가적인 단계 무엇이 calculation.and을 포함 할 필요가 넣으십시오 :

Bundle b = getIntent().getExtras(); 
String answer = b.getString("answer"); 

답변은 당신의 열쇠입니다. 번들에서 얻고 자하는 것을 식별하는 데 사용됩니다. 고유 한 키를 사용하면 원할 경우 하나 이상의 값을 다음 활동으로 전달할 수 있습니다.

+1

첫 번째 활동 수업에서 코드를 수정했지만 앱을 실행할 때마다 앱이 충돌하고 있습니다. 내 활동 클래스는 다음과 같습니다. – abhishek

+0

코드를 게시하지 않았습니다. 그것을 보여주기 위해서는 약간의 혼란이 필요합니다. – NotACleverMan

관련 문제