나는 세 가지 다른 클래스가 있으며 class1에있는 을 클릭하면 class3의 TextView
이 "50"으로 변경되기를 원합니다. 반면에 class2의 ImageButton
을 클릭하면 class3의 TextView가 "0"으로 변경됩니다.두 가지 다른 활동의 데이터를 다른 활동으로 전달하는 방법
클래스 1 :
ImageButton button1 = (ImageButton) this.findViewById(R.id.imageButton);
if (button1 != null) {
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent passdata_intent1 = new Intent(class1.this, class3.class);
String data1 = "50";
Bundle bundle1 = new Bundle();
bundle1.putString("firstdata", data1);
passdata_intent1.putExtras(bundle1);
startActivity(passdata_intent1);
}
});
}
Class2의 :
ImageButton button1 = (ImageButton) this.findViewById(R.id.imageButton);
if (button1 != null) {
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent passdata_intent2 = new Intent(class2.this, class3.class);
String data2 = "0";
Bundle bundle2 = new Bundle();
bundle2.putString("seconddata", data2);
passdata_intent2.putExtras(bundle2);
startActivity(passdata_intent2);
}
});
}
강좌 3 :
TextView score = (TextView) findViewById(R.id.textViewscore);
Bundle bundle1 = getIntent().getExtras();
String data_1 = bundle1.getString("firstdata");
score.setText(data_1);
Bundle bundle2 = getIntent().getExtras();
String data_2 = bundle2.getString("seconddata");
score.setText(data_2);
그래서 내 문제는 내가 응용 프로그램을 시작할 때 나는 Class2의에 ImageButton
클릭이다 클래스 3의 TextView
이 변경됩니다. 그러나 class1에서 ImageButton
을 클릭하면 class3에서 아무 것도 변경되지 않습니다.
Bcoz는 score.setText();를 두 번 설정했습니다. 따라서 매번 마지막 메소드 호출은 텍스트 뷰 내에서 첫 번째 값 데이터를 표시하지 않습니다. – sushildlh