2

i have textfile and i manage to display it in listview , my problem is that i want to remove the duplicate entries in column Category, Code,Description when displayed in listview. Thank you for helping! //here is my textfile with duplicate entries

//here is my code in displaying

public ArrayList<HashMap<String, String>> getAllProducts() {
        ArrayList<HashMap<String, String>> proList;
        proList = new ArrayList<HashMap<String, String>>();
        String selectQuery = "SELECT * FROM Countsheet";
        SQLiteDatabase database = this.getWritableDatabase();
        Cursor cursor = database.rawQuery(selectQuery, null);

        if (cursor.moveToFirst()) {
            do {

                HashMap<String, String> map = new HashMap<String, String>();

                map.put("Category", cursor.getString(1));
                map.put("Code", cursor.getString(2));
                map.put("Description", cursor.getString(3));
                map.put("Unit", cursor.getString(4));
                map.put("Quantity", cursor.getString(5));
                proList.add(map);
            } while (cursor.moveToNext());
        }

        return proList;
    }
RaRa
  • 67
  • 11
  • You should basically look into how to remove duplicates from a HashMap. Here is a good start http://stackoverflow.com/questions/21625772/how-to-remove-duplicate-value-from-hash-map – ekeith Dec 27 '16 at 02:37
  • Will a SELECT DISTINCT not solve the requirement? – rob2universe Dec 27 '16 at 02:38
  • @RobE - when i used distinct my app keeps on crashing dont know why – RaRa Dec 27 '16 at 02:53
  • Without error? What does the attempt and the resulting error look like? – rob2universe Dec 27 '16 at 02:54
  • @Calypso thanks ill try this and inform you as soon as possilbe thank you – RaRa Dec 27 '16 at 02:55
  • @RobE - i forgot , i need to retain the unit i just need to remove duplicate entries in column category , code, description IM SORRY I FORGOT TO SPECIFY:( – RaRa Dec 27 '16 at 03:12
  • @Calypso - i forgot , i need to retain the unit i just need to remove duplicate entries in column category , code, description IM SORRY I FORGOT TO SPECIFY:( – RaRa Dec 27 '16 at 03:13
  • If you want to aggregate the units per category and have only one row per category then a GROUP BY clause would help. – rob2universe Dec 27 '16 at 04:21
  • @RobE - ok sir ill try that THANKS! – RaRa Dec 27 '16 at 04:24

0 Answers0