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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:29:36+00:00 2026-05-26T09:29:36+00:00

I parse 2 elements, TD tags from a website by doing 2 for loops

  • 0

I parse 2 elements, TD tags from a website by doing 2 for loops with JSoup.
I want them to diplay next to each other in a Listview, like this:

naam: waarde 
naam: waarde 

But they are shown like this in the Listview, which gets filled by a CustomBaseAdapter.

naam: 
naam: 
naam: 
waarde 
waarde 
waarde 

Can somebody please help me to get this done? This is keeping me busy for quit some time now.

Any other suggestions are also welcome, thank you.

The 2 for loops, with which the lists, “naam” and “waarde” get filled:

 Document doc = Jsoup.parse(kpn);  
   Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)"); 
   Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)"); 
   SearchResults sr1 = new SearchResults(); 

      for (Element tdFromSecondColumn : tdsFromSecondColumn) {                            
           sr1 = new SearchResults(); 
           sr1.setNaam(tdFromSecondColumn.text()); 
           results.add(sr1); 
      } 

      for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {                              
           sr1 = new SearchResults(); 
           sr1.setWaarde(tdFromSecondColumn1.text()); 
           results.add(sr1); 
      } 

I know it should be something like this, but how?:

for (Element tdFromSecondColumn : tdsFromSecondColumn) {                             
     sr1 = new SearchResults();  
     sr1.setNaam(tdFromSecondColumn.text());  
     sr1.setWaarde(tdFromSecondColumn1.text());
     results.add(sr1);  

}

Here is my CustomeBaseAdapter:

public class MyCustomBaseAdapter extends BaseAdapter { 

private static ArrayList<SearchResults> searchArrayList; 

private LayoutInflater mInflater; 


  public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results) { 
  searchArrayList = results; 
  mInflater = LayoutInflater.from(context); 
  } 


public int getCount() { 
  return searchArrayList.size(); 
} 

public Object getItem(int position) { 
  return searchArrayList.get(position); 
} 

public long getItemId(int position) { 
  return position; 
} 

public View getView(int position, View convertView, ViewGroup parent) { 
    ViewHolder holder; 
  if (convertView == null) { 
    convertView = mInflater.inflate(R.layout.test, null); 
    holder = new ViewHolder(); 
    holder.txtNaam = (TextView) convertView.findViewById(R.id.naam); 
    holder.txtWaarde = (TextView) convertView.findViewById(R.id.waarde); 

    convertView.setTag(holder); 
   } else { 
 holder = (ViewHolder) convertView.getTag(); 
 } 

 holder.txtNaam.setText(searchArrayList.get(position).getNaam()); 
 holder.txtWaarde.setText(searchArrayList.get(position).getWaarde()); 

 return convertView; 
} 

static class ViewHolder { 
  TextView txtNaam; 
  TextView txtWaarde; 
} 


} 

Edit:
I have now someting like this but get exception indexsize 12:

public ArrayList<SearchResults> GetSearchResults(){

          ArrayList<SearchResults> results = new ArrayList<SearchResults>();
          ArrayList<SearchResults> results1 = new ArrayList<SearchResults>();
          ArrayList<SearchResults> results2 = new ArrayList<SearchResults>();

          Document doc = Jsoup.parse(kpn);  
          Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
          Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");

          SearchResults sr1 = new SearchResults();
          SearchResults sr2 = new SearchResults();


          for (Element tdFromSecondColumn : tdsFromSecondColumn) {                             
               sr1 = new SearchResults();  
               sr1.setNaam(tdFromSecondColumn.text());  
               results.add(sr1);  
          }  

          for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {                               
               sr2 = new SearchResults();  
               sr2.setWaarde(tdFromSecondColumn1.text());  
               results1.add(sr2);  
          }  

          for (int i = 0; i < results.size();i++) { 
              results.add(results.get(i));
              results2.add(results1.get(i)); 
            } 

          return results2;

         }
     }

Edit2:
Exception is gone but it only shows the of results1 i.a setWaarde:

public ArrayList<SearchResults> GetSearchResults(){

          ArrayList<SearchResults> results = new ArrayList<SearchResults>();
          ArrayList<SearchResults> results1 = new ArrayList<SearchResults>();
          ArrayList<SearchResults> results2 = new ArrayList<SearchResults>();

          Document doc = Jsoup.parse(kpn);  
          Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
          Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");

          SearchResults sr1 = new SearchResults();
          SearchResults sr2 = new SearchResults();


          for (Element tdFromSecondColumn : tdsFromSecondColumn) {                             
               sr1 = new SearchResults();  
               sr1.setNaam(tdFromSecondColumn.text());  
               results.add(sr1);  
          }  

          for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {                               
               sr1 = new SearchResults();  
               sr1.setWaarde(tdFromSecondColumn1.text());  
               results1.add(sr1);  
          }  

          for (int i = 0; i < results.size() && i < results1.size();i++) { 
              results.add(results.get(i));
              results2.add(results1.get(i)); 
            } 

          return results2;

         }
     }
  • 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-05-26T09:29:37+00:00Added an answer on May 26, 2026 at 9:29 am

    +1 to what Chris said. Also, if you’re trying to combine those two loops, you can’t do it with that syntax. Just use the simple counting method, e.g.

    for(Object o : oList1) {
        doStuff(o);
    }
    
    for (Object o : oList2) {
        doStuff2(o);
    }
    

    becomes

    for (int i = 0; i < oList1.size() && i < oList2.size(); i++) {
        doStuff(oList1.get(i));
        doStuff2(oList2.get(i));
    }
    

    Of course, this assumes the two lists are the same length, otherwise one of the lists won’t be fully consumed. If they vary, you COULD use OR instead of AND in the loop and check each one for null before acting on it, but you’re probably better off just using two separate loops.

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

Sidebar

Related Questions

I have 2 elements tags which i want to add to 2 edittexts of
Trying to parse an HTML document and extract some elements (any links to text
I parse a big xml document with Sax, I want to stop parsing the
I parse some values from an xml file. There is a @25-12-2010'T'23:40:00 string with
I parse an xml file containing books, for each new node I go: Book
I parse in the XML using from lxml import etree tree = etree.parse('test.xml', etree.XMLParser())
Original I want to parse a string of html code and add newlines after
I am using lxml to parse xml I got from amazon product advertisement API.
I have a scenario where I want to parse through all the values displayed
I need to parse sections from a string of HTML. For example: <p>Lorem ipsum

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.