0

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 :)

3
  • 1
    What do you want to see? You can add views to LinearLayout, not strings. Commented Feb 3, 2020 at 10:27
  • 1
    The code line <string name= "title_activity_driver_map" >Map</string> is not valid here. Cut it from here and paste it in file res/values/strings.xml Commented Feb 3, 2020 at 10:27
  • 1
    what do you want to achieve you can add views not string file in main layout Commented Feb 3, 2020 at 10:50

3 Answers 3

2

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> 
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.