2

I have two parts(two fragments: first fragment covers 60% of the screen and second occupies remaining.) on a single screen. In the first fragment I placed gridview and in the second fragment I created tableLayout. In the gridView I have placed 36 ediTexts. In the down tablelayout I designed custom keypad. As I need the ten edittexts to be displayed as exactly fit on the first fragment, I disabled the vertical scrollbar for the gridview. Even though it works somewhat on emulator when in portrait mode, It is not working in landscape. So, I decided to get the height of the fragment first, so is there any way to get the fragment height and width. Even after getting the measures, how to make my edittexts to fit to the current fragment when modes are changed? Though I searched sources, couldn't find the clear solution for it. Below is my code.Any suggestions would be greatly appreciated. Thanks in advance.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <FrameLayout
                android:id="@+id/fLayout1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:background="@drawable/background3">
        <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
                android:id="@+id/gridview"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:columnWidth="18dp"
                android:numColumns="9"
                android:verticalSpacing="0dp"
                android:horizontalSpacing="5dp"
                android:stretchMode="columnWidth"
                android:gravity="center"
                android:listSelector="@null"/>
        </FrameLayout>

        <FrameLayout
                android:id="@+id/fLayout2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="4"
                android:background="@drawable/background2">

        <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/keypad"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:stretchColumns="*">

        <TableRow>
        <Button android:id="@+id/keypad_1"
        android:text="1"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_2"
        android:text="2"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_3"
        android:text="3"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_4"   
        android:text="4"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_5"
        android:text="5"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>



        <Button android:id="@+id/keypad_6"
        android:text="6"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_7"
        android:text="7"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_8"
        android:text="8"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_9"
        android:text="9"
        android:background="@drawable/custombutton"> 
        </Button>

        <Button android:id="@+id/keypad_10"
        android:text="C"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>
        <Button android:id="@+id/submit"
        android:text="validate"
        android:layout_span="5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/custombutton">

        </Button>
        </TableRow>
        </TableLayout>

        </FrameLayout>
</LinearLayout>
Kanth
  • 6,681
  • 3
  • 29
  • 41

1 Answers1

0

A gridView is always scrollable. You can create a custom one that has fixed size (there are example somewhere)

If you know you'll have 10 elements, use a static layout (using a tablelayout for instance)

njzk2
  • 38,969
  • 7
  • 69
  • 107
  • Sorry, I have 36 edittexts. So it was simple and accomplished 36 edittexts with Adapter class. If I use table layout or some other layout it makes the code lengthy. – Kanth Sep 04 '12 at 10:12
  • true. you can try to make a custom non-scrollable gridview. The trick is to modify onMeasure. see the answer to this question http://stackoverflow.com/questions/4523609/grid-of-images-inside-scrollview – njzk2 Sep 04 '12 at 12:08
  • Hi, Can you please tell me where I am getting error. As you suggested I have created custom gridview. when I add the following code in my activity class, The application is showing that "the application has stopped unexpectedly". gridView = (ExpandableHeightGridView) findViewById(R.id.myId); gridView.setAdapter(new TextAdapter(this)); – Kanth Sep 06 '12 at 05:30
  • post a new question with the code and the complete stacktrace – njzk2 Sep 06 '12 at 07:29