4

I'm showing a dialog when the user clicks a button. When the dialog appears and you click an EditText to enter some text, you can't see the bottom buttons (and the lowest EditText) anymore. So you have to click the keyboard down, then select the button or EditText. I searched for the answer for a while now, but i can't find it.

So: How do i make my dialog scrollable? Apparently my code doesnt do the trick:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">

<EditText         
   android:id="@+id/addKlantNaam"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/klantNaam" 
   />

<EditText         
   android:id="@+id/addKlantLocatie"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/klantLocatie" 
   />

<TextView
    android:id="@+id/scheidenDoorKomma"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:text="@string/scheidenDoorKomma"/>

<EditText         
   android:id="@+id/addFabrieken"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/fabrieken" 
   />

 <EditText        
   android:id="@+id/addMachines"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/machines" 
   />

 <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/dialogAnnuleren"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="@string/annuleren"
        android:textSize="22sp" />

    <Button
        android:id="@+id/dialogToevoegen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"   
        android:layout_toRightOf="@+id/dialogAnnuleren"     
        android:textSize="22sp"
        android:text="@string/toevoegen"/>
  </RelativeLayout>

</LinearLayout>

This is how i call for the dialog:

btnAdd.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {

            // custom dialog
            dialog = new Dialog(context);
            dialog.setContentView(R.layout.addklant_layout);
            dialog.setTitle("Klant toevoegen");

            Button BTNannuleren = (Button) dialog.findViewById(R.id.dialogAnnuleren);
            // if button is clicked, close the custom dialog
            BTNannuleren.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            Button BTNtoevoegen = (Button) dialog.findViewById(R.id.dialogToevoegen);
            // if button is clicked, close the custom dialog
            BTNtoevoegen.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    StoreKlantInDatabase task = new StoreKlantInDatabase();     
                        task.execute(urlInsertKlant);
                        dialog.dismiss();
                    }
            });      
            dialog.show();
      }
    });

anyone can help me out here?

GeertG
  • 158
  • 2
  • 12
  • 1
    from what I know there is no way to make a dialog or an activity scrollable... just a view like listview or scrollview...so your option is to arrange your Views differently or create onfocus change that closes the keyboard on outside press, but getting the keyboard will always block part of your interface... either that or arrange them differently or smaller sizes – Jony-Y Oct 01 '13 at 06:46
  • Btw you should use wrap_content or match_parent instead of fill_parent – Jony-Y Oct 01 '13 at 06:48
  • ah, thats a pity:p My app is gonna run on different sizes, so i don't wanna give the dialog a pre-defined height. So i guess practically my only option is to edit the keyboard and let the user go to the next EditText on pressing enter? Because constantly closing and opening the keyboard seems annoying to me. – GeertG Oct 01 '13 at 06:50
  • In the scrollview or in the lineairlayout? – GeertG Oct 01 '13 at 06:51
  • Scrollview has only one child in it as far as i know...so i dont think its a solution...if you want ill show you how i used mine...but you should also know that different devices require different resolution so almost certainly you would have to change dims for xlarge an large or normal sized devices...and dont give it a predefined hight... scale things you should always try to use wrap_content or match_parent – Jony-Y Oct 01 '13 at 06:54
  • try using onfocuse change to close the keyboard,but yeah... unless you hardcode the keyboard it will close and open...most apps work like that... its not uncommon – Jony-Y Oct 01 '13 at 06:56
  • oh, oke thanks. Yes please, can you show how you used yours? You can post it as an answer i guess. – GeertG Oct 01 '13 at 06:56
  • http://stackoverflow.com/questions/4259607/if-scrollview-only-supports-one-direct-child-how-am-i-supposed-to-make-a-whole – Jony-Y Oct 01 '13 at 06:59
  • try this it might work – Jony-Y Oct 01 '13 at 06:59
  • damn, doesnt work either :s I guess it's just not possible the way i would like it:p – GeertG Oct 01 '13 at 07:04

3 Answers3

1

GeertG... now im emotionally involved :) try the link i found... it might do the trick as far as using a scrollview with more than a single child...I dont know if it solves your issue but... If ScrollView only supports one direct child, how am I supposed to make a whole layout scrollable?

or

how to add multiple child in horizontal scroll view in android

Those solutions should work as creating a scrollview with more than 1 child... will it solve your problem? IDK...

also look in to

How to hide soft keyboard on android after clicking outside EditText?

but having the keyboard closed and re-opened seems kinda reasonable to me... dont linger on it for too long:)

Community
  • 1
  • 1
Jony-Y
  • 1,579
  • 1
  • 13
  • 30
  • Haha, thanks;) I've tryed the links, but i guess the simple fact is that it's not possible. I'm gonna use android:imeOptions="actionDone" and android:singleLine="true" to make the keyboard hide on enter. You're right, i'll accept the fact that the keyboard goes down and pops up;) Thanks for your help. – GeertG Oct 01 '13 at 07:28
  • Lets say I hope thats the biggest issue your gonna face:) not a biggy... hope I helped:) – Jony-Y Oct 01 '13 at 07:35
1

The guidelines for what you are asking are can be found here. As you can see. there are a number of ways to achieve what you are asking.

Further to this, you could consider changing default action of the 'Enter' button on the keyboard to select the next EditText and finally to submit the form when you are done (read up about it here):

android:imeOptions="actionDone"
CodeMonkey
  • 1,426
  • 1
  • 14
  • 32
0

Use LinearLayout Height match_parent. And try if its working or not.

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44