Skip to content Skip to sidebar Skip to footer

Trouble To Fill Listview Correctly

I am getting some data from the net, which gets parsed with JSoup in a AsyncTask. I am having trouble filling the listview correctly. Edit1 only gets filled with empty fields (..)

Solution 1:

Try this,

@Override 
    protectedvoidonPostExecute(String result) { 
        // create the grid item mapping
        ListView kp = (ListView)findViewById(R.id.kpn);

        String[] from = new String[] {"col_1", "col_2"};
        int[] to = newint[] { R.id.editText1, R.id.editText2 };

        List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
        List<HashMap<String, String>> fillMaps1 = new ArrayList<HashMap<String, String>>();
          List<HashMap<String, String>> fill_Maps = new ArrayList<HashMap<String, String>>();

 HashMap<String, String> map;
 HashMap<String, String> map1;


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

        for (Element tdFromSecondColumn : tdsFromSecondColumn) {

                  map = new HashMap<String, String>();
                  map.put("col_1", tdFromSecondColumn.text()); 
            fillMaps.add(map);

            System.out.println("Hashmap: " + map);

        } 
        for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
                           map1 = new HashMap<String, String>();                                      map1.put("col_2", tdFromSecondColumn1.text());
            fillMaps1.add(map1);

            System.out.println("Hashmap1: " + map1);
        }

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

               fill_Map.add(fillMap.get(i));
               fill_Map.add(fillMap1.get(i));
}
        SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fill_Map, R.layout.test, from, to); 
        kp.setAdapter(adapter);

And let me know what happen..

Post a Comment for "Trouble To Fill Listview Correctly"