1

Here is my code:

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;    

    AlertDialog alertChoice = new AlertDialog.Builder(context).create();
    alertChoice.setTitle("Title");
    alertChoice.setView(ViewDialogScreen("Test"));    
    alertChoice.show();    
  }
  private View ViewDialogScreen(String strText) {
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(320, 400));
    TextView tv = new TextView(context);
    tv.setText(strText);
    llay.addView(tv);
    return llay;
  }

enter image description here

I got the output like the above.

  1. I need to show the AlertDialog in full screen / 95% of the Screen size.
  2. I need to handle more fields in the Dialog.
  3. How do I enable the HorizontalScrollview in the AlertDialog?
Kev
  • 118,037
  • 53
  • 300
  • 385
Finder
  • 1,217
  • 5
  • 18
  • 46

3 Answers3

1

to get the scrolling behaviour, add a surrounding ScrollView to your layout, which would make your ViewDialogScreen method to this:

private View ViewDialogScreen(String strText) {
    ScrollView scroll = new ScrollView(context);
    scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    TextView tv = new TextView(context);
    tv.setText(strText);
    scroll.addView(llay);
    llay.addView(tv);
    return scroll;
}

Now try adding some more fields and it should scroll.

Michael Rose
  • 7,770
  • 3
  • 22
  • 26
  • I already try that.I can able to Scroll in the Vertical manner only but I need to scroll in the Horizontal Manner.When I add the HorizontalScroll it's not working .Then after setting the LayoutParams I got the same Screen size only. – Finder Apr 07 '11 at 07:04
  • If you want horizontal scrolling, replace `ScrollView` with `HorizontalScrollView` and it will automatically add horizontal scrolling when the maximum width is reached. However, there is currently no widget allowing you to scroll horizontally and vertically at the same time (google it). But the dialog will stretch vertically as far as possible. – Michael Rose Apr 07 '11 at 07:17
  • Thanks . I got the Horizontal Scrolling.But I need to Show Alert in full screen. – Finder Apr 07 '11 at 07:21
  • As far as I have tried it, I found no other solution than just letting it stretch itself... sorry that I am no help at this point. If you really need the full-screen perhaps try creating a new Activity. – Michael Rose Apr 07 '11 at 07:23
  • Thanks for your Kind help Michael Rose. – Finder Apr 07 '11 at 07:37
  • @karthick Well the only solution I came up with after some research is described [here](http://groups.google.com/group/android-developers/browse_thread/thread/343168f6917cb076) which uses a `Dialog` instead of an `AlertDialog`: `Dialog alertChoice = new Dialog(context, android.R.style.Theme_Light); alertChoice.setTitle("Title"); alertChoice.setContentView(ViewDialogScreen("TestTestTest")); alertChoice.show(); ` – Michael Rose Apr 07 '11 at 09:45
  • Great!! Thank you Very Much Michael Rose – Finder Apr 07 '11 at 10:20
0

I am not sure this but you can set your own layout for dialog. Refer my answer Android: Dialog dismisses without calling dismiss

Community
  • 1
  • 1
Vivek
  • 4,170
  • 6
  • 36
  • 50
0

If you want to customize an AlertDialog you need to create a Custom Dialog.

Wroclai
  • 26,835
  • 7
  • 76
  • 67