我有一個名爲AddPlayerFragment的片段,它需要一些字符串。我是這樣做的..從一個片段發送值到另一個片段
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Add Player");
// Set an EditText view to get user input
final EditText input = new EditText(getActivity());
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
dialog.dismiss();
return;
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
return;
}
});
return alert.show();
}}
我想從變量值該字符串值讓我叫Scorecard_Fragment另一個片段。我絕對是Android開發的初學者。任何建議?我有一些線索可以通過Bundle或Intent做到,但不知道怎麼做!
解決了這個問題.. – muktoshuvro
Bundle bundle = new Bundle(); bundle.putString(「message」,value); MyBundles.scorePLayer = value; ((Scorecard_Fragment)MainActivity.getFragment())。scorePlayer(value); – muktoshuvro