Back to project page ProjectStudio.
The source code is released under:
Apache License
If you think the Android project ProjectStudio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package dialog_fragments; /*from w ww. j av a 2 s. c o m*/ import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import com.example.uniutilproject.R; public class MatesDialogFragment extends DialogFragment { private EditText searchfield; private CheckBox search_by_name = null; private CheckBox search_by_email = null; public static MatesDialogFragment newInstance(String title) { MatesDialogFragment frag = new MatesDialogFragment(); Bundle args = new Bundle(); args.putString("mates_title", title); frag.setArguments(args); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { String btnOk = "Submit"; String btnCancel = "Cancel"; // create the new fragment using the alert builder String title = getArguments().getString("mates_title"); AlertDialog.Builder ad = new AlertDialog.Builder(getActivity()); ad.setTitle(title); // Get the Layout inflater // pass null as the parent view because its going in the dialog layout LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.mates_dialogview, null); // Inflate and set the layout for the dialog ad.setView(view); //get views searchfield = (EditText) view.findViewById(R.id.mates_dialog_et); search_by_name = (CheckBox) view.findViewById(R.id.mates_searchbyname); search_by_email = (CheckBox) view.findViewById(R.id.mates_searchbyemail); // add action buttons ad.setPositiveButton(btnOk, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Send the positive button event back to the host activity doPositiveClick(); } }); ad.setNegativeButton(btnCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Send the negative button event back to the host activity doNegativeClick(); } }); //Create the dialog box and perform other operations on it final AlertDialog dialog = ad.create(); //Call the keyboard to show automatically dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); return dialog; } // Methods for custom dialog fragment private void doPositiveClick() { Toast.makeText(getActivity(), "OK button pressed", Toast.LENGTH_LONG) .show(); Log.i("FragmentAlertDialog", "Positive click!"); } private void doNegativeClick() { Toast.makeText(getActivity(), "Negative button pressed", Toast.LENGTH_LONG).show(); Log.i("FragmentAlertDialog", "Negative click!"); } }