1

I'm trying to fill an AlertDialog with a WebView and a CheckBox with the following RelativeLayout:

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

    <WebView
        android:id="@+id/webcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"  />
    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/webcontent"
        android:layout_marginLeft="7dp"
        android:textColor="#ffffff"     />

</RelativeLayout>

According to my research here and here. In my code, instead of using the alertDialog.setMessage(), I used the above layout by calling alertDialog.setView(...) and then it works well for the short text. When the WebView content becomes very long that I need to scroll several times to reach the buttom, the CheckBox can't be displayed even when scrolling to buttom of the webview. Could somebody help me? Thanks in advance.

Community
  • 1
  • 1
Dreamer
  • 563
  • 1
  • 8
  • 25

2 Answers2

1

You need a scrollbar. The method alertDialog.setMessage() puts the text into a textview with a scrollbar as parent, thus long text is working. But alertDialog.setView() puts a view into a framelayout, as you can see in the android code: /data/res/layout/alert_dialog.xml

<LinearLayout android:id="@+id/contentPanel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical">
    <ScrollView android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="2dip"
        android:paddingBottom="12dip"
        android:paddingLeft="14dip"
        android:paddingRight="10dip"
        android:overScrollMode="ifContentScrolls">
        <TextView android:id="@+id/message"
            style="?android:attr/textAppearanceMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dip" />
    </ScrollView>
</LinearLayout>
<FrameLayout android:id="@+id/customPanel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">
    <FrameLayout android:id="@+android:id/custom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:paddingBottom="5dip" />
</FrameLayout>

I could not use this xml either, because long text will overlap the custom view. The following should work:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/webcontent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="7dp"
            android:textColor="#ffffff" />
    </LinearLayout>

</ScrollView>
alphalima
  • 11
  • 1
0

I know its late, but here is what worked for me. With this approach, the check-box appears at the bottom and does not move when the Web View is scrolled (i.e. only the Web View scrolls).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" 
  android:gravity="left"
  android:paddingTop="12dp"
  android:paddingLeft="12dp">

  <WebView 
    android:id="@+id/tip_webView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

  <CheckBox
    android:id="@+id/tip_checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Do not display again"
    android:textColor="#000"
    android:paddingTop="12dp" />    

</LinearLayout>
dazed
  • 352
  • 3
  • 9