-2
您好,我有一個活動,我想從它傳遞值到一個對話框並在對話框文本框中顯示該值。 以下是包含我想傳遞給對話框的EditText的活動。如何將活動中的值傳遞給對話框並在Android Studio中顯示它
p.java。
public class piku_daily extends AppCompatActivity {
private LayoutInflater inflater;
String total = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_piku_daily);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public void Onclick(View v){
Button button = (Button)v;
String str = button.getText().toString();
total+=str;
EditText edit = (EditText)findViewById(R.id.piku_weka);
edit.setText(total);
}
public void Onclear(View v){
EditText edit = (EditText)findViewById(R.id.piku_weka);
total="";
edit.setText("");
}
public void Onplay(View v){
Mydialog dialog = new Mydialog();
dialog.show(getFragmentManager(), "Confirmation_Dialog");
}}
對話框代碼
public class Mydialog extends DialogFragment {
LayoutInflater inflater;
View v;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState){
inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.pikupop, null);
TextView textview = (TextView) v.findViewById(R.id.piku_value);
textview.setText(""+700);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(v).setPositiveButton("Ndio", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setNegativeButton("Hapana", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
return builder.create();
}}
我能請得到,我怎麼能做到這一點
我沒有得到你的觀點正確的價值,我想在對話框中使用isEditText edit =(EditText)findViewById(R.id.piku_wek); – user3337660