Max Harrison
Max Harrison

Reputation: 13

LinearLayout not declaring

I'm having trouble with the following code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <string name= "title_activity_driver_map" >Map</string></LinearLayout>

The LinearLayout is not declaring. I'm not sure why I've used the tag Linear Layout elsewhere on my project and it works fine with the same 1st line of code.

Would appreciate any help :)

Upvotes: 0

Views: 242

Answers (3)

zahra
zahra

Reputation: 98

I think you want show a tex in layout but use incorrect way. in android at first you should declare layout like linear,relative ,... and in body of layout you can put all thing such as button ,textview,edittext,... in your case you can use linearlayout and in body of layout put textview and set the text of text of it map as you want like this. if you want to have better code you can put the text in stringMap in values folders strings.xml file. res>values>strins.xml like the code below.

<resources>
    <string name="app_name">app_name</string>
    <string name= "title_activity_driver_map" >Map</string>
</resources>

and after that you can set the text in textview that you declare in layout like below

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title_activity_driver_map"/>

    </LinearLayout>

good luck

Upvotes: 1

Jamil Hasnine Tamim
Jamil Hasnine Tamim

Reputation: 4448

Put your string<string name= "title_activity_driver_map" >Map</string> in values folders strings.xml file. res>values>strins.xml

<resources>
    <string name="app_name">app_name</string>
    <string name= "title_activity_driver_map" >Map</string>
</resources>

Then declare this string in your layout xml:

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title_activity_driver_map"/>

    </LinearLayout>

Upvotes: 0

Dipankar Baghel
Dipankar Baghel

Reputation: 2039

I think you want like this below -

add required height and width to LinearLayout this is important for container and put TextView inside Layout to show the string value, move <string name= "title_activity_driver_map" >Map</string> inside res/values/strings.xml and give reference in layout

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title_activity_driver_map"/>

    </LinearLayout>

Upvotes: 2

Related Questions