Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:36:54+00:00 2026-06-07T04:36:54+00:00

i am working on my first project with android and java and have very

  • 0

i am working on my first project with android and java
and have very little experience.
i have a radio player (start and stop button that activates a service)
and
some data from a xml file like artist title and album loaded in a textview
i use a timer so that the gui updates with the song played

this all works
only when the lyrics are loaded in the textview it only shows the first line of the xml tag <LYRIC>

this is my main activity:

extends  Activity implements OnClickListener{

     private static final String TAG = "ServicesDemo";
     public String myimageURL;
     private EditText Lyrics;
    private ImageView AlbumPic;
    private Button play,  stop;
    private TextView Artist, Song, Album, News, Lyric;
    private UpdateTimeTask m_updateTime;
    private Handler m_handler;
    Parser data;
    /** The delay in milliseconds between updates. */
    private final int DELAY = 20000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Artist =(TextView)findViewById(R.id.tvArtist);
        Song  =(TextView)findViewById(R.id.tvSongTitle);
        Album =(TextView)findViewById(R.id.tvAlbum);
        play = (Button) findViewById(R.id.play);
        stop = (Button) findViewById(R.id.stop);
        Lyrics = (EditText) findViewById(R.id.tvLyrics);
        News = (TextView)findViewById(R.id.tvAnouncement);
        AlbumPic = (ImageView) findViewById(R.id.AlbumPic);



        play.setOnClickListener(this);
        stop.setOnClickListener(this);



        m_updateTime = new UpdateTimeTask();

        m_handler = new Handler();
        m_handler.post(m_updateTime);
    }

    private class UpdateTimeTask implements Runnable {
        public void run() {


            try {

                SAXParserFactory saxPF = SAXParserFactory.newInstance();
                SAXParser saxP = saxPF.newSAXParser();
                XMLReader xmlR = saxP.getXMLReader();


                URL url = new URL("http://www.mysite.com/AndroidTest.php"); 
                XMLHandler myXMLHandler = new XMLHandler();
                xmlR.setContentHandler(myXMLHandler);
                xmlR.parse(new InputSource(url.openStream()));

            } catch (Exception e) {
                System.out.println(e);
            }
            data = XMLHandler.data;



            for (int i = 0; i < data.getTitle().size(); i++) {

           Lyrics.setText(data.getLyric().get(i));
                 myimageURL = data.getPic().get(i);

            Song.setText("Title = "+data.getTitle().get(i));


            Artist.setText("Artist = "+data.getArtist().get(i));


            Album.setText("Album = "+data.getAlbum().get(i)); 






 }

 downloadFile(myimageURL );

}

Bitmap bmImg;
void downloadFile(String fileUrl) {
 URL myFileUrl = null;
 try {
    myFileUrl = new URL(fileUrl);
 } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
 }
 try {
    HttpURLConnection conn = (HttpURLConnection) myFileUrl
          .openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream is = conn.getInputStream();

    bmImg = BitmapFactory.decodeStream(is);
    AlbumPic.setImageBitmap(bmImg);
 } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
 }
 m_handler.postDelayed(m_updateTime, DELAY);
 AlbumPic.clearAnimation();
}

}

my xml code

<?xml version="1.0"?>
<CATALOG>
<CD>
<LYRIC>Stop that train: I'm leavin' - today!
Stop that train: I'm leavin' - anyway!
Stop that train: I'm leavin'. and I said:
It won't be too long whether I'm right or wrong;
I said, it won't be too long whether I'm right or wrong.

All my good life I've been a lonely man,
Teachin' my people who don't understand;
And even though I tried my best,
I still can't find no happiness.

So I got to say:
Stop that train: I'm leavin' - oh, baby now!
Stop that train: I'm leavin' - don't care what you say!
Stop that train: I'm leavin'. and I said:
It won't be too long whether I'm right or wrong;
Said, it won't be too long whether I'm right or wrong.

Some goin' east; and-a some goin' west,
Some stand aside to try their best.
Some livin' big, but the most is livin' small:
They just can't even find no food at all.

I mean, stop it:
Stop that train: I'm leavin' - leavin', mm-hmm.
Stop that train: I'm leavin' - I don't mind!
Stop that train: I'm leavin'. and I said:
It won't be too long whether I'm right or wrong;
I said it won't be too long whether I'm right or wrong.

Stop that train: I'm leavin' - leavin'!
Stop that train: I'm leavin' - can't take it!
Stop that train: I'm leavin' - got to be better!
It won't be too long whether I'm right or wrong;
I said it won't be too long whether I'm right or wrong.</LYRIC>
<ARTIST>Bob Marley</ARTIST>
<TITLE>Stop That Train</TITLE>
<ALBUM>Talkin blues</ALBUM>
<PIC>http://www.mysite.com/Android/Radio/AlbumCovers/Bob-Marley-Talkin-blues.jpg</PIC>
</CD>
</CATALOG>

i also tried to load the lyrics using edittext but there it also only show the first line of the <LYRIC> tag

can someone give some advice how to show the whole text in the textview

thanks

my xmlhandler

public class XMLHandler extends DefaultHandler {

    String elementValue = null;
    Boolean elementOn = false;
    public static Parser data = null;

    public static Parser getXMLData() {
        return data;
    }

    public static void setXMLData(Parser data) {
        XMLHandler.data = data;
    }

    /** 
     * This will be called when the tags of the XML starts.
     **/
    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {

        elementOn = true;

        if (localName.equals("CATALOG"))
        {
            data = new Parser();
        } else if (localName.equals("CD")) {
            /** 
             * We can get the values of attributes for eg. if the CD tag had an attribute( <CD attr= "band">Akon</CD> ) 
             * we can get the value "band". Below is an example of how to achieve this.
             * 
             * String attributeValue = attributes.getValue("attr");
             * data.setAttribute(attributeValue);
             * 
             * */
        }
    }

    /** 
     * This will be called when the tags of the XML end.
     **/
    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {

        elementOn = false;

        /** 
         * Sets the values after retrieving the values from the XML tags
         * */ 
        if (localName.equalsIgnoreCase("title"))
            data.setTitle(elementValue);
        else if (localName.equalsIgnoreCase("artist"))
            data.setArtist(elementValue);
        else if (localName.equalsIgnoreCase("album"))
            data.setAlbum(elementValue);
        else if (localName.equalsIgnoreCase("lyric"))
            data.setLyric(elementValue);
        else if (localName.equalsIgnoreCase("pic"))
            data.setPic(elementValue);


    }

    /** 
     * This is called to get the tags value
     **/
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

        if (elementOn) {
            elementValue = new String(ch, start, length);
            elementOn = false;
        }

    }

    public void post(Runnable mUpdate) {
        // TODO Auto-generated method stub

    }

    public void removeCallbacks(Runnable sendUpdatesToUI) {
        // TODO Auto-generated method stub

    }

    public void postDelayed(Runnable runnable, int i) {
        // TODO Auto-generated method stub

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:36:55+00:00Added an answer on June 7, 2026 at 4:36 am

    I advice you to check you XMLHandler object. I suspect you have something wrong there.

    If you can show us your XMLHandler class that would be better to help you.

    EDIT:

    I have made some changes to your handler. I think you might have a problem when you read the element value. Use a CharArrayWriter instead (I’ve resolve an identical problem with that).
    And I think you doesn’t need the ‘elementOn’ too. If its a non necessary variable just don’t use it.
    Make sure you have too a multine TextView defined on your XML layout.
    Hope it works 🙂

    public class XMLHandler extends DefaultHandler {
    
        private static final String TAG = "XMLHandler";
        private String elementValue = null;
        public static Parser data = null;
    
        /** The contents. */
        private CharArrayWriter contents = new CharArrayWriter();
    
        public static Parser getXMLData() {
            return data;
        }
    
        public static void setXMLData(Parser data) {
            XMLHandler.data = data;
        }
    
        /** 
         * This will be called when the tags of the XML starts.
         **/
        @Override
        public void startElement(String uri, String localName, String qName,
                Attributes attributes) throws SAXException {
    
            /**It´s a good practice to reset the CharArrayWriter when you start any element.*/
            contents.reset();
    
            if (localName.equals("CATALOG"))
            {
                data = new Parser();
            } else if (localName.equals("CD")) {
                /** 
                 * We can get the values of attributes for eg. if the CD tag had an attribute( <CD attr= "band">Akon</CD> ) 
                 * we can get the value "band". Below is an example of how to achieve this.
                 * 
                 * String attributeValue = attributes.getValue("attr");
                 * data.setAttribute(attributeValue);
                 * 
                 * */
            }
        }
    
        /** 
         * This will be called when the tags of the XML end.
         **/
        @Override
        public void endElement(String uri, String localName, String qName)
                throws SAXException {
            /** 
             * Sets the values after retrieving the values from the XML tags
             * */ 
             String elementValue = contents.toString().trim();
    
            if (localName.equalsIgnoreCase("title"))
                data.setTitle(elementValue);
            else if (localName.equalsIgnoreCase("artist"))
                data.setArtist(elementValue);
            else if (localName.equalsIgnoreCase("album"))
                data.setAlbum(elementValue);
            else if (localName.equalsIgnoreCase("lyric"))
                data.setLyric(elementValue);
            else if (localName.equalsIgnoreCase("pic"))
                data.setPic(elementValue);
        }
    
        /** 
         * This is called to get the tags value
         **/
        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
                contents.write(ch, start, length);
        }
    
        @Override
        public void endDocument() throws SAXException {
            Log.i(TAG, "Catalog parse finalized with success.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a little Android project in java, I'm using the webapi of
Im working on a school project and it's my first time on android development.
I’m currently working on a Android project and is very newbie to the Android
I'm working on my first Android project, and I'm starting off by making a
I'm working on my first Android project, and I created a menu via the
I'm working on an android project that involves native code and I'm trying to
I am working on my first project using ExtJS. I have a Data Grid
I am working on a android project and I have my four tabs. On
I am working on my first android project. i am doing a maos based
I'm working on my first project using Python 2.7. We're coming from a Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.