通过背景颜色区分视图

我想区分视图的背景颜色,但我不知道该怎么做。谁能帮我完成任务。


下面是我的 DatabaseHelper.java 类


public  List<HouseModal> get_Working_Area_Structures_House(int limit, int offset,String searched_Str) {

    if(database == null){

        database = getWritableDatabase();

    }

    List<HouseModal> list_krd= new ArrayList<>();


    String selectQuery = "SELECT DISTINCT\n" +

            "\tWAS.Para_Structure_ID,\n" +

            "\tWAS.Para_Code || '   ' || CAST (WAS.Structure_No AS int) AS Structure_No,\n" +

            "\tST.Family_Count AS Families,\n" +

            "\tFM.Family_Members_Count AS Family_Members, \n" +

            "\t FM.Family_Migration AS Family_Migration\n" +

            "FROM\n" +

            "\t (\n" +

            "\t\t SELECT\n" +

            "\t\t\tP.Para_Code,\n" +

            "\t\t\tPS.Para_Structure_ID,\n" +

            "\t\t\tPS.Structure_No \n" +

            "\t\tFROM\n" +

            "\t\t\tPara_Structure AS PS\n" +

            "\t\tINNER JOIN  Working_Area_Structures AS WAS ON PS.Para_Structure_ID = WAS.Para_Structure_ID\n" +

            "\t\tINNER JOIN  Field_Station_Paras AS P ON PS.Para_ID = P.Para_ID \n" +

            "\t) AS WAS,\n" +

            "\t (\n" +

            "\tSELECT\n" +

            "\t\t\tKH.Para_Structure_ID,\n" +

            "\t\t\tCOUNT(DISTINCT KH.House_Hold_ID) AS Family_Count \n" +

            "\t\tFROM\n" +

            "\t\t\tKhandan_Register_Header AS KH\n" +

            "\t\tLEFT JOIN  Family_Visit_History AS FVH ON KH.House_Hold_ID = FVH.House_Hold_ID \n" +

            "\t\tWHERE\n" +

            "\t\t(FVH.Visit_Status = 0 OR FVH.Visit_Status IS NULL)\n" +

            "\t\t--AND ((date(FVH.Visit_Date) >= (SELECT date(Starting_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date)) AND date(FVH.Visit_Date) <= (SELECT date(Ending_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date))) OR date(FVH.Visit_Date) IS NULL) \n" +


明月笑刀无情
浏览 123回答 2
2回答

蝴蝶刀刀

放if(holder.structureID.isEmpty(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view.findViewById(R.id.structureID).setBackgroundColor(Color.parseColor("#CFD8DC")); //light gray&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view.findViewById(R.id.structureID).setBackgroundColor(Color.parseColor("#FDFDE9")); //light yellow&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }在 if(view == null) 之外并进入 else 块,以便在重绘时获得更改,因为 recyclerview 将重用单元格,并且需要更改的任何内容(文本、值、颜色)都需要也重新申请编辑:只是为了澄清 - 如果您更改 getView() 方法以便您只为viewHolder 对象在 if/else 语句中,然后在下面更改视图本身所需的所有值,它最终会变得更清晰、更易于阅读

RISEBY

如果您的项目为空,如何更改它的颜色或如何检查它?null 为空。您应该检查 Null 以确保崩溃的安全性而不改变颜色。如果您想更改颜色,您应该从数据库中获取一个特定字段,该字段显示此列中没有值或为空。然后你可以检查它的颜色
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java