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

  • Home
  • SEARCH
  • 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 9210559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:06:27+00:00 2026-06-18T01:06:27+00:00

I’m trying to parse an XML and display its contents in table layout. I’m

  • 0

I’m trying to parse an XML and display its contents in table layout. I’m adding rows and columns dynamically, when execute instead of displaying table, it shows a blank screen.

This is my xml file.

<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"
tools:context=".CaptureActivity" >

<ScrollView
android:id="@+id/ScrollView_maintable"
android:layout_width="match_parent"
android:layout_height="400dp" >

<TableLayout
    android:id="@+id/main_table"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_weight="1" >

 </TableLayout>

This is my activity class.

public class CaptureActivity extends Activity {

private String url = "http://192.168.3.140:8080/EmployeeXmlDemo/EmployeeList.xml";
//private String url = "http://192.168.2.166:8780/capture/clientRequest.do?r=employeeList&cid=0";

FetchEmployeeAsyncTask employeeAsyncTask = new FetchEmployeeAsyncTask(this);

private ArrayList<Employee> employees = null;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    employeeAsyncTask.execute(new String[] {url});

    System.out.println("Status "+employeeAsyncTask.getStatus());

    setContentView(R.layout.activity_capture);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_capture, menu);
    return true;
}



public void showEmployees(ArrayList<Employee> employees) {
    // TODO Auto-generated method stub
    System.out.println("size is "+employees.size());

    TableLayout employeeTable = (TableLayout) findViewById(R.id.main_table);

    TableRow header = new TableRow(this);
    header.setId(100);
    //header.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    TextView empCodeHeader = new TextView(this);
    empCodeHeader.setId(200);
    empCodeHeader.setText("Employee Code");
    empCodeHeader.setTextSize(16);
    empCodeHeader.setPadding(2,2,2,2);
    empCodeHeader.setWidth(200);
    header.addView(empCodeHeader);

    TextView empNameHeader = new TextView(this);
    empNameHeader.setId(201);
    empNameHeader.setText("Employee Name");
    empNameHeader.setTextSize(16);
    empNameHeader.setPadding(2,2,2,2);
    empNameHeader.setWidth(300);
    header.addView(empNameHeader);

    employeeTable.addView(header);//, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));



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

        Employee employee = (Employee) employees.get(i);

        int count = 0;

        TableRow empData = new TableRow(this);
        empData.setId(300+count);
        /*empData.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT ));*/
        //tr.setClickable(true);

        final TextView empCode = new TextView(this);
        empCode.setId(300+count);
        empCode.setText(employee.getCode());
        empCode.setTextSize(16);
        empCode.setPadding(2,2, 2, 2);
        empData.addView(empCode);

        final TextView empName = new TextView(this);
        empName.setId(300+count);
        empName.setText(employee.getName());
        empName.setTextSize(16);
        empName.setPadding(2, 2, 2, 2);
        empData.addView(empName);

        employeeTable.addView(empData); /*, new TableLayout.LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));*/
       count++;

        System.out.println("Name "+employee.getName());
        System.out.println("Designatio "+employee.getDesignation());


    }
    setContentView(R.layout.activity_capture);

}



/**
 * @return the employees
 */
public ArrayList<Employee> getEmployees() {
    return employees;
}

/**
 * @param employees the employees to set
 */
public void setEmployees(ArrayList<Employee> employees) {
    this.employees = employees;
}

}

This is my AsyncTask class.

public class FetchEmployeeAsyncTask extends AsyncTask<String, Void, ArrayList<Employee> >   {

private CaptureActivity activity;

public FetchEmployeeAsyncTask(CaptureActivity nextActivity) {
    this.activity = nextActivity;
}

@Override
protected ArrayList<Employee> doInBackground(String... url) {
    // TODO Auto-generated methoVoidd stub
    ArrayList<Employee> employees = null;
    for(String employeeUrl : url){
        employees = fetch(employeeUrl);
    }
    return employees;
}

private ArrayList<Employee> fetch(String url) {
    // TODO Auto-generated method stub
    ArrayList<Employee> employees = null;
    String response = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        response = EntityUtils.toString(httpEntity);
        employees = EmployeeXMLParser.XMLfromString(response);
        System.out.println("Size in fetch "+employees.size());

        //System.out.println("Employee Name :: " + employees.get(0).getFirstName() + " " + employees.get(0).getLastName());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } /*catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        System.out.println("Error parsing the response :: " + response);
        e.printStackTrace();
    }*/
    return employees;
}

@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
}

@Override
public void onPostExecute(ArrayList<Employee> employees){
    super.onPostExecute(employees);

    System.out.println("in post execxute "+employees.size());
    activity.showEmployees(employees);
    //activity.setContentView(R.layout.activity_capture);

}


}
  • 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-18T01:06:28+00:00Added an answer on June 18, 2026 at 1:06 am
     setContentView(R.layout.activity_capture)
    

    remove that in showEmployee()

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i want to parse a xhtml file and display in UITableView. what is the
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to render a haml file in a javascript response like so:

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.