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 7899089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:36:28+00:00 2026-06-03T08:36:28+00:00

I am A new guy in Android. I try to develop a list that

  • 0

I am A new guy in Android. I try to develop a list that can show the song name and author at the same line. The source data is from a online XML file

The following is the code I try to use in my program.
However, I only be able to display the author name in the list.
I would to ask how I should modify the code so that I can show the song name and author at the same line in the list?

The Format of online XML file I try to read

<recipes>
<song>
    <id>1</id>
    <title>Sing A Song</title>
    <songs_author>ACM</songs_author>
</song>
<song>
    <id>2</id>
    <title>DO Re Me</title>
    <songs_author>BBC/songs_author>
</song>
</recepies>

src/com.mobile/SongsActivity

package com.mobile;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class SongsActivity extends Activity implements OnItemClickListener {

    protected static final int DIALOG_KEY = 0;
    ListView mListView;
    Button mClear;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        this.setProgressBarIndeterminateVisibility(false);

        setContentView(R.layout.Songs);

        mListView = (ListView) findViewById(R.id.listView1);
        mListView.setTextFilterEnabled(true);
        mListView.setOnItemClickListener(this);


        LoadRecipesTask1 mLoadRecipesTask = new LoadRecipesTask1();
        mLoadRecipesTask.execute("http://123.com/mobile/Songs_list.php");          



        mClear = (Button) findViewById(R.id.button3);
        mClear.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mListView.setAdapter(null);
            }
        });

    }



    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Datum datum = (Datum) mListView.getItemAtPosition(position);
        Uri uri = Uri.parse("http://123.com/mobile/Songs.php?Songsid=" + datum.getId());
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        this.startActivity(intent);
    }

    public static ArrayList<Datum> parse(String url) throws IOException, XmlPullParserException {
        final ArrayList<Datum> results = new ArrayList<Datum>();

        URL input = new URL(url);

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();

        xpp.setInput(input.openStream(), null);
        int eventType = xpp.getEventType();
        String currentTag = null;
        Integer id = null;
        String title = null;
        String Songs_author = null;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                currentTag = xpp.getName();
            } else if (eventType == XmlPullParser.TEXT) {
                if ("id".equals(currentTag)) {
                    id = Integer.valueOf(xpp.getText());
                }
                if ("title".equals(currentTag)) {
                    title = xpp.getText();
                }
                if ("Songs_author".equals(currentTag)) {
                    Songs_author = xpp.getText();
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if ("song".equals(xpp.getName())) {
                    results.add(new Datum(id, title, Songs_author));
                }
            }
            eventType = xpp.next();
        }
        return results;
    }

    protected class LoadRecipesTask1 extends AsyncTask<String, Void, ArrayList<Datum>> {

        @Override
        protected void onPreExecute() {
            SongsActivity.this.setProgressBarIndeterminateVisibility(true);
        }

        @Override
        protected ArrayList<Datum> doInBackground(String... urls) {
            ArrayList<Datum> datumList = new ArrayList<Datum>();
            try {
                datumList = parse(urls[0]);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
            return datumList;
        }




        @Override
        protected void onPostExecute(ArrayList<Datum> result) {





            mListView.setAdapter(new ArrayAdapter<Datum>(SongsActivity.this, R.layout.list_item, result));
            //SongsActivity.this.setProgressBarIndeterminateVisibility(false);
        }
    }



}

src/com.mobile/Datum

package com.mobile;

public class Datum {

    int id;
    String title;
    String songs_author;

    public Datum(int id, String title, String songs_author) {
        this.id = id;
        this.title = title;
        this.songs_author= songs_author;
    }

    public String toString() {
        return songs_author;
    }

    public int getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String get Songs_author() {
        return Songs_author;
    }

}

res/layout/songs.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="horizontal" android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <Button android:text="Refresh 1" android:id="@+id/button1"
                        android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
                <Button android:text="Clear" android:id="@+id/button3"
                        android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
        </LinearLayout>
        <ListView android:id="@+id/listView1" android:layout_height="fill_parent"
                android:layout_width="fill_parent"></ListView>
</LinearLayout>

res/layout/list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>
  • 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-03T08:36:29+00:00Added an answer on June 3, 2026 at 8:36 am

    Just make Custom List View using array adapter.

    refer this example..

    http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m a new guy to c# and I try to add a some code
I'm a new guy in PHP OOP concepts. One of the first things that
I'm a new Ruby/Rails guy. Here's one question puzzling me: Can we find the
I'm totally new to iOS programing (I'm more an Android guy..) and have to
i am the new guy in WPF. I want to display employer list effectively.
New guy here so bear with me. Ive got a basic XSL file that
im just new in AS3 so i have a question hope you guy can
So I am an old web forms guy and new to the MVC (in
I have never developed for WAMP, the hosting guy for my new client says
new_story GET /story/new(.:format) {:action=>new, :controller=>stories} edit_story GET /story/edit(.:format) {:action=>edit, :controller=>stories} story GET /story(.:format) {:action=>show,

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.