如何在android中为当前日期着色?

如何在android中为当前日期着色?,android,Android,我的日历上有这个代码。我想给今天涂上颜色,但它在所有月份都会给今天涂上颜色。例如今天15/05我的代码颜色15/05、15/06、15/07、15/08。。。。。。 我该怎么做我需要你的帮助 编辑 public View getView(int位置、视图转换视图、视图组父视图){ 视图行=转换视图; if(行==null){ LayoutInflater充气器=(LayoutInflater)\u上下文 .getSystemService(上下文布局\充气机\服务); 行=充气机。充气(R.la

我的日历上有这个代码。我想给今天涂上颜色,但它在所有月份都会给今天涂上颜色。例如今天15/05我的代码颜色15/05、15/06、15/07、15/08。。。。。。 我该怎么做我需要你的帮助

编辑

public View getView(int位置、视图转换视图、视图组父视图){
视图行=转换视图;
if(行==null){
LayoutInflater充气器=(LayoutInflater)\u上下文
.getSystemService(上下文布局\充气机\服务);
行=充气机。充气(R.layout.screen\u gridcell,父项,false);
}
//获取对Day gridcell的引用
gridcell=(按钮)row.findViewById(R.id.calendar\u day\u gridcell);
setOnClickListener(this);
//说明间距
d(标记“当前日期:+getCurrentDayOfMonth());
String[]day\u color=list.get(position).split(“-”);
字符串theday=day\u color[0];
字符串themonth=day_color[2];
字符串theyear=day_color[3];
如果((!eventspermontmap.isEmpty())&&(eventspermontmap!=null)){
if(eventsPerMonthMap.containsKey(当天)){
每天事件数=(文本视图)行
.findViewById(R.id.num\u每天的事件);
整数numEvents=(整数)eventsPerMonthMap.get(theday);
num_events_per_day.setText(numEvents.toString());
}
}
//在单元格中设置日期
gridcell.setText(theday);
setTag(日期+“-”+月份+“-”+年份);
Log.d(标记,“设置网格单元格”+日期+“-”+月+“-”
+年份);
如果(day_颜色[1]。等于(“灰色”)){
setTextColor(getResources())
.getColor(R.color.lightgray));
}
如果(day_color[1]。等于(“白色”)){
getResources().getColor(
R.color.lightgray02);
}
如果(day_color[1]。等于(“蓝色”)){
setTextColor(getResources().getColor(R.color.orrange));
}
getJSON();
返回行;
}
私有void getJSON(){
类GetJSON扩展异步任务{
对话加载;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
加载=ProgressDialog.show(getActivity(),“Téléchargement”,“Veuillez patientez…”,false,false);
}
@凌驾
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
loading.dispose();
JSON_STRING=s;
JSONObject JSONObject=null;
//ArrayList=新建ArrayList();
试一试{
jsonObject=新的jsonObject(JSON_字符串);
JSONArray result=jsonObject.getJSONArray(TAG_JSON_数组);
num=result.length();
如果(天颜色[1]。等于(“蓝色”)&&num>0){
setTextColor(getResources().getColor(R.color.orrange));
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
@凌驾
受保护字符串doInBackground(无效…参数){
RequestHandler rh=新的RequestHandler();
字符串s=rh.sendGetRequest(URL);
返回s;
}
}
GetJSON gj=new GetJSON();
gj.execute();
}
@凌驾
公共void onClick(视图){
字符串date\u month\u year=(字符串)view.getTag();
//selectedDayMonthYearButton.setText(“Selected:+日期、月份、年份”);
Log.e(“选定日期”,日期、月份、年份);
试一试{
Date parsedDate=dateFormatter.parse(日期、月份、年份);
Log.d(标记“已解析日期:”+parsedDate.toString());
}捕获(解析异常){
e、 printStackTrace();
}
final String log=et_login.getText().toString().trim();
Intent Intent=新的Intent(getActivity(),RendezVousListe.class);
意向。额外(“日期选择”,日期、月份、年份);
意向。额外(“日志”,日志);
星触觉(意向);
}
public int getCurrentDayOfMonth(){
返回currentDayOfMonth;
}
私有无效设置currentDayOfMonth(int currentDayOfMonth){
this.currentDayOfMonth=currentDayOfMonth;
}
公共无效setCurrentWeekDay(int currentWeekDay){
this.currentWeekDay=currentWeekDay;
}public int getCurrentWeekDay(){
返回当前工作日;
}
php代码

<?php 
        $log1= $_POST['log'];
        $dat= $_POST['dateR'];
        require_once('dbConnect.php');
        $sql = "SELECT * FROM rendezvous WHERE LoginD = '$log1' and DateR='$dat'";

    //getting result 
    $r = mysqli_query($con,$sql);

    //creating a blank array 
    $result = array();
    $res = mysqli_num_rows($r):
    //looping through all the records fetched
    while($row = mysqli_fetch_array($r)){

        //Pushing name and id in the blank array created 
        array_push($result,array(
            "id"=>$row['id'],
            "LoginM"=>$row['LoginM'],
            "HeureR"=>$row['HeureR']


        ));
    }

    //Displaying the array in json format 
    echo json_encode(array('result'=>$result));

    mysqli_close($con);

此代码的问题(在所有其他问题中)在于它不区分月份/年份。如果您想让此代码仅在当前月份中选择当前日期,则只需在
打印月份
方法中添加月/年检查

因此,更改
printmount
方法的这部分代码:

    // Current Month Days
    for (int i = 1; i <= daysInMonth; i++) {
        Log.d(currentMonthName, String.valueOf(i) + " "
                    + getMonthAsString(currentMonth) + " " + yy);
        if (i == getCurrentDayOfMonth()) {
            list.add(String.valueOf(i) + "-BLUE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
        } else {
            list.add(String.valueOf(i) + "-WHITE" + "-"
                    + getMonthAsString(currentMonth) + "-" + yy);
        }
    }
//当前月份天数

对于(int i=1;i,此代码的问题(在所有其他问题中)在于它不区分月份/年
    // Current Month Days
    for (int i = 1; i <= daysInMonth; i++) {
        Log.d(currentMonthName, String.valueOf(i) + " "
                    + getMonthAsString(currentMonth) + " " + yy);
        if (i == getCurrentDayOfMonth()) {
            list.add(String.valueOf(i) + "-BLUE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
        } else {
            list.add(String.valueOf(i) + "-WHITE" + "-"
                    + getMonthAsString(currentMonth) + "-" + yy);
        }
    }
    Calendar calendar = Calendar.getInstance();

    // Current Month Days
    for (int i = 1; i <= daysInMonth; i++) {
        Log.d(currentMonthName, String.valueOf(i) + " "
                + getMonthAsString(currentMonth) + " " + yy);
        if (i == getCurrentDayOfMonth() && calendar.get(Calendar.MONTH) == currentMonth && calendar.get(Calendar.YEAR) == yy) {
            list.add(String.valueOf(i) + "-BLUE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
        } else {
            list.add(String.valueOf(i) + "-WHITE" + "-"
                        + getMonthAsString(currentMonth) + "-" + yy);
        }
    }