-2

Hello i have an Activity that i want to pass values from it to a Dialog and Display That value in a Dialog Textview. The following is the activity that contains EditText that i want to pass to the Dialog.

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");
}}

The Dialog codes are

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();

}}

Can i please get an help on how i can do that

user3337660
  • 35
  • 1
  • 7

1 Answers1

0

Make a static method on you dialog like this :

public static MyDialog myDialog(Value what u need){
   MyDialog myDialog = new MyDialog();
   return myDialog;
}

After that you can call this method on your activity. It will return with your dialog, and you can use .show on it. On the static method you can save your value.

Robert Banyai
  • 1,329
  • 12
  • 14
  • i didn't get your point right the value that i want to use in the dialog isEditText edit = (EditText)findViewById(R.id.piku_wek); – user3337660 Apr 03 '16 at 11:06