Skip to content

Instantly share code, notes, and snippets.

@CreatorB
Created September 22, 2018 00:40
Show Gist options
  • Save CreatorB/f15e9174fff8473f16d3d6e5a46e50a7 to your computer and use it in GitHub Desktop.
Save CreatorB/f15e9174fff8473f16d3d6e5a46e50a7 to your computer and use it in GitHub Desktop.
custom dialog android
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showMyDialog(this);
}
public void showMyDialog(final Activity activity) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
LayoutInflater inflater = activity.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.my_custom_dialog, null);
dialogBuilder.setView(dialogView);
final TextView tvJudul = (TextView) dialogView.findViewById(R.id.tvTitle);
tvJudul.setText("My Title");
dialogBuilder.setTitle(activity.getString(R.string.setting_lang));
dialogBuilder.setPositiveButton(activity.getString(R.string.act_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int position = spinner1.getSelectedItemPosition();
changeLang(activity, position);
}
});
// dialogBuilder.setNegativeButton(activity.getString(R.string.setting_cancel), new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {
// dialog.dismiss();
// }
// });
AlertDialog b = dialogBuilder.create();
b.show();
b.setCancelable(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment