나는 다음 활동으로 다른 값 (1 또는 2)을 전달하려는 스위치 버튼이 있습니다. 그러나 나는 항상 0을 얻습니다. 어떤 도움이 필요합니까? 다음 활동에서안드로이드 인 텐트는 스위치에서 값을 전달하지 않습니다
Switch mySwitch = (Switch) findViewById(R.id.edit_home);
// set the switch to ON
mySwitch.setChecked(true);
// attach a listener to check for changes in state
mySwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
double input5 = 2;
Intent intentx=new Intent(MainActivity.this,Main2Activity.class);
intentx.putExtra("IFValue",input5);
startActivity(intentx);
Toast.makeText(getApplicationContext(), "Home field is important advantage",
Toast.LENGTH_SHORT).show();
} else {
double input5 = 1;
Intent intenty=new Intent(MainActivity.this,Main2Activity.class);
intenty.putExtra("IFValue",input5);
startActivity(intentx);
Toast.makeText(getApplicationContext(),
"Home field is not advantage", Toast.LENGTH_SHORT).show();
}
}
});
:
Bundle bundle = getIntent().getExtras();
double input5 = bundle.getDouble("IFValue");
편집 : 나는 (INPUT5) 다음 활동에 값을 보내려고합니다,하지만 난 startActivity를 추가하면 (intentx) 스위치의 내부; 다음 버튼을 누를 때마다 즉시 이동합니다. 원하는대로 버튼 (buttonForward)을 누르십시오. 코드의
나머지 :
당신은 수신기 내부의Intent
(& intentx intenty)의 로컬 인스턴스를 만들
Switch mySwitch = (Switch) findViewById(R.id.edit_home);
// set the switch to ON
mySwitch.setChecked(true);
// attach a listener to check for changes in state
mySwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked == true) {
double input5 = 2;
Intent intentx=new Intent(MainActivity.this,Main2Activity.class);
intentx.putExtra("IFValue",input5);
startActivity(intentx);
Toast.makeText(getApplicationContext(), "Home field is important advantage",
Toast.LENGTH_SHORT).show();
} else {
double input5 = 1;
Intent intenty=new Intent(MainActivity.this,Main2Activity.class);
intenty.putExtra("IFValue",input5);
startActivity(intenty);
Toast.makeText(getApplicationContext(),
"Home field is not advantage", Toast.LENGTH_SHORT).show();
}
}
});
Button buttonForward = (Button) findViewById(R.id.buttonToMain2);
buttonForward.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
EditText edit_team = (EditText) findViewById(R.id.edit_team);
EditText edit_form = (EditText) findViewById(R.id.edit_form);
EditText edit_import = (EditText) findViewById(R.id.edit_import);
String ekipa1 = edit_team.getText().toString();
final double input2 = Double.valueOf(qualityControl.getProgress());
final double input3 = Double.valueOf(edit_form.getText().toString());
final double input4 = Double.valueOf(ratingBar.getRating());
final double input6 = Double.valueOf(edit_import.getText().toString());
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("Value",input2);
intent.putExtra("Value1",input3);
intent.putExtra("Value2",input4);
intent.putExtra("Value4",input6);
intent.putExtra("team1", ekipa1);
startActivity(intent);
}
});
내가 그것을 PLS startActivty (의도)입니다 breakeposints –
에서 먼저 확인 변경하지 않을 생각 당신의 IsChecked 값을 확인; 그는 청취자를 클릭 buttonForward 기능? 어떻게 다음 활동을 시작하셨습니까? – Hulk
@BhanuSharma 어떻게 해결할 수 있습니까? – user3041073