android-alertdialog

getActivity() where it is defined?

一笑奈何 提交于 2019-12-17 22:23:22
问题 I'm very new to android and I'm following this example. The code says we need to do these steps to get an dialog box: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // 2. Chain together various setter methods to set the dialog characteristics builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title); // 3. Get the AlertDialog from create() AlertDialog dialog = builder.create(); But where does the getActivity() method is defined? I can't find that

Fragment null must be a public static class to be properly recreated from instance state

拟墨画扇 提交于 2019-12-17 21:11:58
问题 I am not able to figure out why my app crashes when getSupportFragmentManager() is called.I have used similar code in other apps to create alert dialogs without any issues.please help! DialogFragment df = new DialogFragment(){ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.addincome,null); builder.setView(view); //capture final

Right justify text in AlertDialog

给你一囗甜甜゛ 提交于 2019-12-17 16:34:46
问题 Is it possible to right-justify the text in an AlertDialog's title and message? I am showing Hebrew messages but they are showing up left justified. 回答1: As far as I can see from the code of AlertDialog and AlertController you can't access the TextView s responsible for message and title. You can use reflection to reach mAlert field in AlertDialog instance, and then again use reflection to access mMessage and mTitle fields of mAlert . Though I wouldn't recommend this approach as it relies on

Closing a custom alert dialog on button click

本秂侑毒 提交于 2019-12-17 16:31:55
问题 I'm having trouble closing my alert dialog. I am using a layout inflator to make the dialog, so I'm not sure how I would go about closing the thing after I'm done with it. Code is below: AlertDialog.Builder dialog = new AlertDialog.Builder(AddData.this); DialogInterface dia = new DialogInterface(); //Create a custom layout for the dialog box LayoutInflater inflater = (LayoutInflater)AddData.this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.add_rep_1_set,

Android:How can I set the AlertDialog width and height,and the button of the AlertDialog style?

风格不统一 提交于 2019-12-17 16:28:52
问题 I have a task to change the AlertDialog width and height by xml,I want make that become style,so I can use it easy.And that ,I need to change button of AlertDialog style also.Can you tell me a way to achieve the target。Thank you Very grateful。 PS,I'd better achieve the target by change xml。 回答1: There are two methods 1) programatically 2) By using xml layout 1)=======> AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(layout); builder.setTitle("Title"); alertDialog

Android Alert Dialog with one, two, and three buttons

三世轮回 提交于 2019-12-17 06:26:29
问题 I don't make alerts very often but every time I do it takes me a while to read through the documentation and figure out how to do it. Since I have had to do this a few times now, I am going to write an answer below that I can come back to in the future. Specifically I want to compare the basic code for One button (OK) Two buttons (OK and Cancel) Three buttons (Positive, Negative, Other) It would be nice to have the basic code for these three common alert types in one spot for easy reference

Transparent AlertDialog has black background

两盒软妹~` 提交于 2019-12-17 04:58:11
问题 I have a custom AlertDialog style that makes the AlertDialog box transparent. It works fine except that when I inflate my desired transparent layout into the alert dialog window, it shows up with a black background. My goal is to have a completely transparent AlertDialog to where it seems as if there are only 4 buttons floating rather than a frame. Image one is what the custom dialog is giving me, image two is my desired or what I am aiming for. Here is the code to the custom Dialog <style

Problem inflating custom view for AlertDialog in DialogFragment

拟墨画扇 提交于 2019-12-17 04:28:19
问题 I'm trying to create a DialogFragment using a custom view in an AlertDialog . This view must be inflated from xml. In my DialogFragment class I have: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle("Title") .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, null)) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null) .create(); } I have tried other inflation

Problem inflating custom view for AlertDialog in DialogFragment

不羁的心 提交于 2019-12-17 04:28:13
问题 I'm trying to create a DialogFragment using a custom view in an AlertDialog . This view must be inflated from xml. In my DialogFragment class I have: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle("Title") .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, null)) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null) .create(); } I have tried other inflation

AlertDialog OnBackPressed() Not Working Properly

断了今生、忘了曾经 提交于 2019-12-14 03:36:34
问题 I've written the following code for simple Alert Dialog but Alert Dialog doesn't show up. API: 26 @Override public void onBackPressed() { super.onBackPressed(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("Are You sure to Exit?") .setTitle("Exit") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MainActivity.super.onBackPressed(); } })