Android_小账本_筛选功能的实现

时间:2022-05-08 18:49:53

昨天对小账本的相关功能做了完善,新增了筛选功能。

Android_小账本_筛选功能的实现

Android_小账本_筛选功能的实现

 

 支持对类型、收支项、日期进行修改。

 但暂时尚不完善,只能针对相关小项进行筛选,无法连续对小项的结果进行筛选。这一功能预计在本周三进行完善。

相关代码

 public String[] readCord_select() {
        SQLiteUserChager sqLiteUserChager = new SQLiteUserChager(getContext(), "Userr", null, 1);
        SQLiteDatabase sqLiteDatabase = sqLiteUserChager.getReadableDatabase();
        number=0;
        if (group.length() < 3) {
            Cursor cursor;
            if (Integer.parseInt(group) == 1) {
                cursor = sqLiteDatabase.rawQuery("select * from Cord where inout=? and username=?", new String[]{select[1][Integer.parseInt(item)],nowusername});
            } else {
                cursor = sqLiteDatabase.rawQuery("select * from Cord where type=? and username=?", new String[]{select[2][Integer.parseInt(item)],nowusername});
            }
            String[] strings = new String[count = cursor.getCount()];
            int i = 0;
            if (cursor.moveToNext())
                do {
                    number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                    String[] strings1 = new String[7];
                    strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                    strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                    strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                    strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                    strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                    strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                    strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                    arr.add(strings1);
                    strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                            " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                            "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                            "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                    i  ;
                } while (cursor.moveToNext());
            cursor.close();
            sqLiteDatabase.close();
            sqLiteUserChager.close();
            tv_sum.setText("总收支:" number);
            return strings;
        } else {                                                                                     //dateselect
            String[] min = group.split("/");
            String[] max = item.split("/");
            Log.d("----max", max[0]   "/"   max[1]   "/"   max[2]);
            Log.d("----min", min[0]   "/"   min[1]   "/"   min[2]);
            Cursor cursor = sqLiteDatabase.rawQuery("select * from Cord where username=?", new String[]{nowusername});
            String[] strings = new String[cursor.getCount()   8000];
            while (cursor.moveToNext()) {
                String date = cursor.getString(cursor.getColumnIndex("date"));
                String[] dats = date.split("/");
                if (Integer.parseInt(dats[0]) > Integer.parseInt(min[0]) && Integer.parseInt(dats[0]) < Integer.parseInt(max[0])) {
                    String[] strings1 = new String[7];
                    number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                    strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                    strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                    strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                    strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                    strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                    strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                    strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                    arr.add(strings1);
                    strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                            " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                            "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                            "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                    i  ;
                } else if (Integer.parseInt(dats[0]) == Integer.parseInt(min[0])) {
                    if (Integer.parseInt(dats[1]) > Integer.parseInt(min[1]) && Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) {
                        String[] strings1 = new String[7];
                        number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                        strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                        strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                        strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                        strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                        strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                        strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                        strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                        arr.add(strings1);
                        strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                                " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                                "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                                "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                        i  ;
                    } else if (Integer.parseInt(dats[1]) == Integer.parseInt(min[1])) {
                        if ((Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) || (Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]))) {
                            String[] strings1 = new String[7];
                            number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                            strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                            strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                            strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                            strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                            strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                            strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                            strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                            arr.add(strings1);
                            strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                                    " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                                    "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                                    "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                            i  ;
                        }
                    } else if (Integer.parseInt(dats[1]) == Integer.parseInt(max[1])) {
                        if ((Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]) && Integer.parseInt(dats[1]) > Integer.parseInt(min[1])) || (Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]))) {
                            String[] strings1 = new String[7];
                            number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                            strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                            strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                            strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                            strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                            strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                            strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                            strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                            arr.add(strings1);
                            strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                                    " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                                    "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                                    "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                            i  ;
                        }
                    }
                } else if (Integer.parseInt(dats[0]) == Integer.parseInt(max[0])) {
                    if (Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) {
                        String[] strings1 = new String[7];
                        number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                        strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                        strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                        strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                        strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                        strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                        strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                        strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                        arr.add(strings1);
                        strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                                " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                                "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                                "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                        i  ;
                    } else if (Integer.parseInt(dats[1]) == Integer.parseInt(max[1])) {
                        if (Integer.parseInt(dats[2]) <= Integer.parseInt(max[2])) {
                            String[] strings1 = new String[7];
                            number =Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                            strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                            strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                            strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                            strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                            strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                            strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                            strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                            arr.add(strings1);
                            strings[i] = "我"   cursor.getString(cursor.getColumnIndex("date"))  
                                    " 在"   cursor.getString(cursor.getColumnIndex("type"))  
                                    "上"   cursor.getString(cursor.getColumnIndex("inout"))  
                                    "了"   cursor.getString(cursor.getColumnIndex("number"))   "元";
                            i  ;
                        }
                    }
                }
            }
            cursor.close();
            sqLiteDatabase.close();
            sqLiteUserChager.close();
            ArrayList<String> arrayList = new ArrayList<>();
            for (int i = 0; i < strings.length; i  ) {
                if (strings[i] != null) {
                    arrayList.add(strings[i]);
                }
            }
            String[] strings2 = new String[arrayList.size()];
            for (int i = 0; i < arrayList.size(); i  ) {
                strings2[i] = arrayList.get(i);
            }
            Log.d("-----gropuitem", group   " "   item);
            tv_sum.setText("总收支:" number);
            return strings2;
        }

    }