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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:54+00:00 2026-06-10T15:58:54+00:00

Right now i am displaying the data from XML file in to grid view

  • 0

Right now i am displaying the data from XML file in to grid view in android.This is the exact xml’s file link

“http://54.251.60.177/StudentWebService/StudentDetail.asmx/GetTMSOrders” which
i am trying to show.I have done that concept successfully, but here the problem is,i am not getting the answer like the below image

i need to show like the below image, in android

enter image description here

but i am getting only like the below image…..

enter image description here

How to overcome this concept?can any one please make me clear?

thanks for your precious time!..

Here my sources for reference,please find

GridviewSample.java

public class GridviewSample extends Activity 
{

// All static variables
static final String URL = "http://54.251.60.177/StudentWebService/StudentDetail.asmx/GetTMSOrders";
// XML node keys
static final String KEY_TABLE = "Table"; // parent node
static final String KEY_CUST = "Cust_Name";
static final String KEY_ORDER = "Order_No";
static final String KEY_FREIGHT = "Freight_Rate";
static final String KEY_STATION1 = "Station_Name";
static final String KEY_STATION2 = "Station_Name1";

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    GridView gv =  (GridView)findViewById(R.id.gridView1);

    ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();

    String xml = parser.getXmlFromUrl(URL); // getting XML

    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_TABLE);

    // looping through all item nodes <item>

    for (int i = 0; i < nl.getLength(); i++) 
    {
        // creating new HashMap

        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);

        // adding each child node to HashMap key => value

        map.put(KEY_CUST, parser.getValue(e, KEY_CUST));
        map.put(KEY_ORDER, parser.getValue(e, KEY_ORDER));
        map.put(KEY_FREIGHT, parser.getValue(e, KEY_FREIGHT));
        map.put(KEY_STATION1, parser.getValue(e, KEY_STATION1));
        map.put(KEY_STATION2, parser.getValue(e, KEY_STATION2));

        // adding HashList to ArrayList
        menuItems.add(map);
    }

    // Adding menuItems to ListView

 SimpleAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.grid_item,
 new String[] { KEY_CUST, KEY_ORDER, KEY_FREIGHT,KEY_STATION1,KEY_STATION2 }, new int[] 
 {
    R.id.cust, R.id.order, R.id.freight,R.id.statio1,R.id.station2 });


    gv.setAdapter(adapter);

    gv.setOnItemClickListener(new OnItemClickListener() 
    {

    public void onItemClick(AdapterView<?> Table, View v,int position, long id) 
    {


    String cust = ((TextView) v.findViewById(R.id.cust)).getText().toString();
    String order = ((TextView) v.findViewById(R.id.order)).getText().toString();
    String freight = ((TextView) v.findViewById(R.id.freight)).getText().toString();
    String station1 = ((TextView) v.findViewById(R.id.statio1)).getText().toString();
    String station2 = ((TextView) v.findViewById(R.id.station2)).getText().toString();

    // Starting new intent

    Intent in = new Intent(getApplicationContext(), Single_gridview_item.class);

      in.putExtra(KEY_CUST, cust);
      in.putExtra(KEY_ORDER, order);
      in.putExtra(KEY_FREIGHT, freight);
      in.putExtra(KEY_STATION1, station1);
      in.putExtra(KEY_STATION2, station2);
      startActivity(in);
      }
    }); 
}   }

Single_gridview_item

public class Single_gridview_item  extends Activity
{

// XML node keys

static final String KEY_TABLE = "Table"; // parent node
static final String KEY_CUST_NAME = "Cust_Name";
static final String KEY_ORDER = "Order_No";
static final String KEY_FREIGHT = "Freight_Rate";
static final String KEY_STATION1 = "Station_Name";
static final String KEY_STATION2="Station_Name1";

@Override
public void onCreate(Bundle savedInstanceState) 
{

    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_grid_item);

    // getting intent data
    Intent in = getIntent();

    // Get XML values from previous intent
    String cust = in.getStringExtra(KEY_CUST_NAME);
    String order = in.getStringExtra(KEY_ORDER);
    String freight = in.getStringExtra(KEY_FREIGHT);
    String station1 = in.getStringExtra(KEY_STATION1);
    String station2 = in.getStringExtra(KEY_STATION2);

    // Displaying all values on the screen

    TextView lblcust = (TextView) findViewById(R.id.cust_label);
    TextView lblorder = (TextView) findViewById(R.id.order_label);
    TextView lblfreight = (TextView) findViewById(R.id.freight_label);
    TextView lblstation1 = (TextView) findViewById(R.id.station1_label);
    TextView lblstation2 = (TextView) findViewById(R.id.station2_label);

    lblcust.setText(cust);
    lblorder.setText(order);
    lblfreight.setText(freight);
    lblstation1.setText(station1);
    lblstation2.setText(station2);
}}

XMLParser.java

public class XMLParser {

// constructor
public XMLParser() {

}

/**
 * Getting XML from URL making HTTP request
 * @param url string
 * */
public String getXmlFromUrl(String url) {
    String xml = null;

    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // return XML
    return xml;
}

/**
 * Getting XML DOM element
 * @param XML string
 * */
public Document getDomElement(String xml){
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is); 

        } catch (ParserConfigurationException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (SAXException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        }

        return doc;
}

/** Getting node value
  * @param elem element
  */
 public final String getElementValue( Node elem ) {
     Node child;
     if( elem != null){
         if (elem.hasChildNodes()){
             for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                 if( child.getNodeType() == Node.TEXT_NODE  ){
                     return child.getNodeValue();
                 }
             }
         }
     }
     return "";
 }

 /**
  * Getting node value
  * @param Element node
  * @param key string
  * */
 public String getValue(Element item, String str) {     
        NodeList n = item.getElementsByTagName(str);        
        return this.getElementValue(n.item(0));
    }}
  • 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-10T15:58:56+00:00Added an answer on June 10, 2026 at 3:58 pm

    Don’t use a grid view, it won’t help you. It is designed to display a list of items as a grid. You may specify the number of columns, but displaying a table is more of a job for a TableLayout.

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

Sidebar

Related Questions

I have a UIScrollView that is displaying a list of data. Right now, when
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
I am displaying the database table values using data tables. I am doing this
I have a page (default.aspx) with a Repeater fetching data from my database, this
I am displaying a scrolled data table in a web page. This table has
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now I have a script that will get the last five files in
Right now, the label for my Activity has the name of the current Activity.

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.