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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:48:39+00:00 2026-06-09T19:48:39+00:00

I am trying to parse an XML file with the following structure: <groups> <group>

  • 0

I am trying to parse an XML file with the following structure:

<groups>
  <group>
    <id>...</id>
    <name>...</name>
    <description>...</description>
    <actions>
      <action>...</action>
      <action>...</action>
    </actions>
  </group>
  <group>
    <id>...</id>
    <name>...</name>
    <description>...</description>
    <actions>
      <action>...</action>
      <action>...</action>
      <action>...</action>
    </actions>
  </group>
  <group>
    <id>...</id>
    <name>...</name>
    <description>...</description>
    <actions>
      <action>...</action>
    </actions>
  </group>
</groups>

Currently in the first ListView I have “name” and “description” visible per row. This is fully functional. When selecting a row a new activity is created with another ListView. It is here where I want to display an action per row based on the selected position in the previous list. How should I do this? I have tried to also add the “action”s to the map where my other items are added to but it only adds 1 “action” per group.
Please advise?

public class ErrorCodeList extends ListActivity {

public static final String LANGUAGE = null;

public ArrayList<HashMap<String, String>> mylist;
public ListAdapter adapter;
public Dialog progDialog;
public ProgressBar progBar;
public TextView lblMessage;

private Intent myIntent;
private String  URLvariable;


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

    myIntent = getIntent();
    URLvariable = myIntent.getExtras().getString("urlType");

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

    adapter = new SimpleAdapter(this, mylist , R.layout.activity_error_list, 
                    new String[] { "tid", "tname" }, 
                    new int[] { R.id.item_id, R.id.item_title });

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")
            HashMap<String, String> hashMap = (HashMap<String, String>) lv.getItemAtPosition(position);                 

            Intent myIntent = new Intent(view.getContext(),ErrorCodeDetails.class);
            myIntent.putExtra("map",hashMap);
            startActivity(myIntent);

        }
    });

    progDialog = new Dialog(this, R.style.progress_dialog);
    progDialog.setContentView(R.layout.progress_dialog);

    progBar = (ProgressBar) progDialog.findViewById(R.id.progBar);
    lblMessage = (TextView) progDialog.findViewById(R.id.txtProgMessage);
    lblMessage.setText("Please Wait.....");

    progDialog.show();
    new GetDataTask().execute();        

}


private Boolean isOnline()  {
    ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if(ni != null && ni.isConnected())
        return true;

    return false;
}

private class GetDataTask extends AsyncTask<Void, Void, Integer> {

    @Override
    protected Integer doInBackground(Void... params) {

        if(isOnline()){
            mylist.clear();                  
            }  

            // Start the http request
            String feedURL="http://...";        
            String xml = XMLfunctions.getXML(feedURL);
            Document doc = XMLfunctions.XMLfromString(xml);

            int numResults = 1;

            if((numResults <= 0)){
                Toast.makeText(ErrorCodeList.this, "Geen resultaten gevonden", Toast.LENGTH_LONG).show();  
                finish();
            }

            NodeList troubles = doc.getElementsByTagName("trouble");

            for (int i = 0; i < troubles.getLength(); i++) {                            
                HashMap<String, String> map = new HashMap<String, String>();    

                Element e = (Element)troubles.item(i);
                if((e.getAttributes().getNamedItem("type").getNodeValue().equals("error"))) {
                    //map.put("id", "ID:" + Integer.valueOf(e.getAttributes().getNamedItem("id").getNodeValue()));
                    //map.put("status", "Status:" + (e.getAttributes().getNamedItem("status").getNodeValue()));
                    map.put("tid", XMLfunctions.getValue(e, "id"));
                    map.put("tname", XMLfunctions.getValue(e, "name"));
                    map.put("tdescription", XMLfunctions.getValue(e, "description"));

                    //NodeList  ns=e.getElementsByTagName("trouble_cause");
                    mylist.add(map);
                }           
            }
            System.out.println(mylist);
        }else{
            Toast.makeText(ErrorCodeList.this, "No connection..", Toast.LENGTH_LONG).show();            
        }

        return 1;
    }

    @Override
    protected void onPostExecute(Integer result) {

        setListAdapter(adapter);
        progDialog.dismiss();
        super.onPostExecute(result);
    }
}

}

  • 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-09T19:48:41+00:00Added an answer on June 9, 2026 at 7:48 pm

    Create a data object Group.

    public class Group {
    private String id;
    private String name;
    private String description;
    private ArrayList<String> actions;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public ArrayList<String> getActions() {
        return actions;
    }
    public void setActions(ArrayList<String> actions) {
        this.actions = actions;
    }
    }
    

    Your activity code will look something like this.

    public class MainActivity extends Activity implements OnItemClickListener {
    
    private ArrayList<Group> groups;
    private ListView list;
    private MyAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = (ListView)findViewById(R.id.my_list);
        list.setAdapter(adapter = new MyAdapter());
        list.setOnItemClickListener(this);
        parseXML();
    }
    
    
    private void parseXML(){
        // TODO: CODE TO PARSE XML
        adapter.notifyDataSetChanged();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
    public class MyAdapter extends BaseAdapter{
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return groups.size();
        }
    
        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return groups.get(0);
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO: Create row view here.
            // USE groups to create list here
            return null;
        }
    
    }
    
    
    @Override
    public void onItemClick(AdapterView<?> listView, View rowView, int position, long column) {
        // TODO Auto-generated method stub
        Group clickedGroup = groups.get(position);
        Intent intent = new Intent(this, SecondActivity.class);
        Bundle bundle = new Bundle();
        bundle.putStringArrayList("ACTIONS", clickedGroup.getActions());
        intent.putExtra("BUNDLE", bundle);
        startActivity(intent);
    }
    
    }
    

    Your second activity will look something like this

    public class SecondActivity extends Activity {
    
    private ArrayList<String> actions;
    private ListView list;
    private ActionAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    
        Intent intent = getIntent();
        Bundle bundle = intent.getBundleExtra("BUNDLE");
        actions = bundle.getStringArrayList("ACTIONS");
    
        list = (ListView)findViewById(R.id.my_list2);
        list.setAdapter(adapter = new ActionAdapter());
    }
    
    
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
    public class ActionAdapter extends BaseAdapter{
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return actions.size();
        }
    
        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return actions.get(0);
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO: Create row view here.
            // USE actions to create list here
            return null;
        }
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file in the following structure. <NewDataSet> <markers> <name>name text</name> <desc>desc
I am trying to parse the following XML file in Java and to store
Is the following format correct for XML? I am trying to parse the file
I'm new to xml parsing, I am trying to parse the following xml file
I am trying to parse an xml log file in PHP. It has following
Im trying to parse the following XML file(generated on iphone with KISSxml) with KissXML
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
Currently, I am trying to parse an online XML file and insert the data
I am trying to parse specific XML file which is located in sub directories
I am trying to parse an XML file with python using lxml, but get

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.