-3

I am developing an android app for beginners to Learn Android I have developed most of it but now Android Studio is showing errors when i tried to paste XML code in text view(that code i want to be visible in TextView).

I did not got much help but i tried to use resources>value>string and tried pasting the code in text field. How can i fix it

<resources>
<string name="textviewcode">Learn Android</string>


 I changed the text(Learn Android) with code and now the app is not working


<string name="textviewcode"><RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

   <TextView
   android:id="@+id/text_id"
   android:layout_width="300dp"
   android:layout_height="200dp"
   android:capitalize="characters"
   android:text="hello_world"
   android:textColor="@android:color/holo_blue_dark"
   android:textColorHighlight="@android:color/primary_text_dark"
   android:layout_centerVertical="true"
   android:layout_alignParentEnd="true"
   android:textSize="50dp"/>

</RelativeLayout></string>
</resources>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kaleem
  • 129
  • 1
  • 14
  • 3
    You want to help others but have issues with basic things? To help you fix your issue, what do you mean with `it is not allowing me to paste XML code in text view`. Who is 'it' and do you see some error? Also, please read https://stackoverflow.com/help/how-to-ask – Zun Jul 23 '19 at 07:53
  • This is my first project to practice android – Kaleem Jul 23 '19 at 07:54
  • 2
    what does it say? Probably you need to escape the special characters like `>` – Vladyslav Matviienko Jul 23 '19 at 07:55
  • Obviously AS. When i pasted the code it shows errors – Kaleem Jul 23 '19 at 07:56
  • @VladyslavMatviienko The prefix "android" for attribute "android:id" associated with an element type "ListView" is not bound. It is just bcz i pasted the xml code – Kaleem Jul 23 '19 at 07:59
  • Saying "obviously AS" doesn't make sense. AS consist of tools like Gradle and Lint. If Lint is telling you the error, then say that. I get it, you're new but if you want help then you need to be detailed. Please refer to the link I posted in the first comment on "how to ask questions on StackOverflow". Describing your issue will help you fix your issue in minutes!!! – Zun Jul 23 '19 at 08:00
  • Show how the code looks like with errors – Vladyslav Matviienko Jul 23 '19 at 08:02
  • @VladyslavMatviienko I have Pasted the brief error message – Kaleem Jul 23 '19 at 08:08
  • that's not what I asked for. Show your code, which throws this error – Vladyslav Matviienko Jul 23 '19 at 08:09
  • I made that change in my app in strings and noe it is not working. – Kaleem Jul 23 '19 at 08:15
  • Don't interpret this the wrong way, but please consider a different project for your first Android app. You want to help others which is nice, but I see more than 4 errors in your example XML code. It's not good to learn new people incorrect/bad code. Please – Zun Jul 23 '19 at 08:21
  • you need to escape the special characters like `>` – Vladyslav Matviienko Jul 23 '19 at 10:00
  • Possible duplicate of [HTML in string resource?](https://stackoverflow.com/questions/2667319/html-in-string-resource) – Vladyslav Matviienko Jul 23 '19 at 10:00

1 Answers1

1

You need to escape your textviewcode value with a CDATA block

Example:

<string name="textviewcode"><![CDATA[YourCodeGoesHere]]></string>

This block allows you to use symbols like < and ' in your value without breaking

Zun
  • 1,553
  • 3
  • 15
  • 26