evc
evc

Reputation: 67

"No XML content. Please add a root view or layout to your document"

I am trying to code a softkeyboard for 2.1 and up when I code ( see code below) in the main.xml graphical view is displays nothing and says No XML content. Please add a root view or layout to your document" I have tried to place the code in textview but still no luck I can not get the softkeyboard to show at all, its as if my code is being ignored..I have tried these two codes separately nothing works

<com.example.android.softkeyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/keyboard"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>
<Keyboard
    android:keyWidth="%10p"
    android:keyHeight="50px"
    android:horizontalGap="2px"
    android:verticalGap="2px" >
   <Row android:keyWidth="32px" >
   <Key android:keyLabel="A" />
...
</Row>
...
</Keyboard>

Upvotes: 1

Views: 6001

Answers (2)

Ghost
Ghost

Reputation: 3966

You need to place a layout as it behaves like a base foundation for your UI. All you need to do is the following:

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

     <com.example.android.softkeyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/keyboard"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>
<Keyboard
    android:keyWidth="%10p"
    android:keyHeight="50px"
    android:horizontalGap="2px"
    android:verticalGap="2px" >
   <Row android:keyWidth="32px" >
   <Key android:keyLabel="A" />
...
</Row>
...
</Keyboard>

    </LinearLayout>

OR

  <?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">

     <com.example.android.softkeyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/keyboard"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>
<Keyboard
    android:keyWidth="%10p"
    android:keyHeight="50px"
    android:horizontalGap="2px"
    android:verticalGap="2px" >
   <Row android:keyWidth="32px" >
   <Key android:keyLabel="A" />
...
</Row>
...
</Keyboard>


    </RelativeLayout>

Linear Layout and Relative Layout are the most widely used layouts in android UI. You can find the tutorial for Linear Layout from here and the tutorial for Relative Layout from here.

Hope this helps.

Upvotes: 0

user936414
user936414

Reputation: 7634

Please put your code in a linear layout

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

<com.example.android.softkeyboard.LatinKeyboardView

android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Keyboard
android:keyWidth="%10p"
android:keyHeight="50px"
android:horizontalGap="2px"
android:verticalGap="2px" >
<Row android:keyWidth="32px" >
<Key android:keyLabel="A" />
...
</Row>
...
</Keyboard>
</LinearLayout>

Upvotes: 1

Related Questions