2016-05-15 4 views
1

Ich habe diesen Code in meinem Kalender. Ich möchte den aktuellen Tag färben, aber es färbe alle aktuellen Tage in allen Monaten. Zum Beispiel heute 15/05 meinen Code Farbe 15/05, 15/06, 15/07, 15/08 ...... Wie kann ich dies tun, ich brauche deine Hilfe bitteWie kann ich aktuellen Tag in Android färben?

bearbeiten

public View getView(int position, View convertView, ViewGroup parent) { 
       View row = convertView; 
       if (row == null) { 
        LayoutInflater inflater = (LayoutInflater) _context 
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        row = inflater.inflate(R.layout.screen_gridcell, parent, false); 
       } 
       // Get a reference to the Day gridcell 
       gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell); 
       gridcell.setOnClickListener(this); 
       // ACCOUNT FOR SPACING 
       Log.d(tag, "Current Day: " + getCurrentDayOfMonth()); 
       String[] day_color = list.get(position).split("-"); 
       String theday = day_color[0]; 
       String themonth = day_color[2]; 
       String theyear = day_color[3]; 
       if ((!eventsPerMonthMap.isEmpty()) && (eventsPerMonthMap != null)) { 
        if (eventsPerMonthMap.containsKey(theday)) { 
         num_events_per_day = (TextView) row 
           .findViewById(R.id.num_events_per_day); 
         Integer numEvents = (Integer) eventsPerMonthMap.get(theday); 
         num_events_per_day.setText(numEvents.toString()); 
        } 
       } 
       // Set the Day GridCell 
       gridcell.setText(theday); 
       gridcell.setTag(theday + "-" + themonth + "-" + theyear); 
       Log.d(tag, "Setting GridCell " + theday + "-" + themonth + "-" 
         + theyear); 
       if (day_color[1].equals("GREY")) { 
        gridcell.setTextColor(getResources() 
          .getColor(R.color.lightgray)); 
       } 
       if (day_color[1].equals("WHITE")) { 
        gridcell.setTextColor(getResources().getColor(
          R.color.lightgray02)); 
       } 
       if (day_color[1].equals("BLUE")) { 
        gridcell.setTextColor(getResources().getColor(R.color.orrange)); 
       } 
getJSON(); 
       return row; 
      } 
private void getJSON() { 
      class GetJSON extends AsyncTask<Void, Void, String> { 
       ProgressDialog loading; 
       @Override 
       protected void onPreExecute() { 
        super.onPreExecute(); 
        loading = ProgressDialog.show(getActivity(), "Téléchargement", "Veuillez patientez...", false, false); 
       } 
       @Override 
       protected void onPostExecute(String s) { 
        super.onPostExecute(s); 
        loading.dismiss(); 
        JSON_STRING = s; 
        JSONObject jsonObject = null; 
        // ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>(); 
        try { 
         jsonObject = new JSONObject(JSON_STRING); 
         JSONArray result = jsonObject.getJSONArray(TAG_JSON_ARRAY); 
         num=result.length(); 
         if (day_color[1].equals("BLUE") && num>0){ 
          gridcell.setTextColor(getResources().getColor(R.color.orrange)); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
       @Override 
       protected String doInBackground(Void... params) { 
        RequestHandler rh = new RequestHandler(); 
        String s = rh.sendGetRequest(URL); 
        return s; 
       } 
      } 
      GetJSON gj = new GetJSON(); 
      gj.execute(); 
     } 
      @Override 
      public void onClick(View view) { 
       String date_month_year = (String) view.getTag(); 
       //selectedDayMonthYearButton.setText("Selected: " + date_month_year); 
       Log.e("Selected date", date_month_year); 
       try { 
        Date parsedDate = dateFormatter.parse(date_month_year); 
        Log.d(tag, "Parsed Date: " + parsedDate.toString()); 

       } catch (ParseException e) { 
        e.printStackTrace(); 
       } 
       final String log = et_login.getText().toString().trim(); 
       Intent intent = new Intent(getActivity(), RendezVousListe.class); 
       intent.putExtra("dateSel", date_month_year); 
       intent.putExtra("log", log); 
       startActivity(intent); 
      } 
      public int getCurrentDayOfMonth() { 
       return currentDayOfMonth; 
      } 
      private void setCurrentDayOfMonth(int currentDayOfMonth) { 
       this.currentDayOfMonth = currentDayOfMonth; 
      } 
      public void setCurrentWeekDay(int currentWeekDay) { 
       this.currentWeekDay = currentWeekDay; 
      }   public int getCurrentWeekDay() { 
       return currentWeekDay; 
      } 

pHP-Code

<?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); 
+0

, müssen Sie Ihre vollständigen Code teilen. Zum Beispiel haben wir keine Ahnung, was die 'day_color' ist – x0r

+0

@ R.Kirill das ist mein Code http://www.androidhub4you.com/2012/10/custom-calendar-in-android.html –

Antwort

0

Das Problem mit diesem Code (bei allen anderen Problemen) ist, dass es zwischen den einzelnen Monaten/Jahren unterscheidet. Wenn Sie diesen Code nur in aktuellen Monat aktuellen Tag auswählen möchten, müssen Sie nur einen Scheck für Monat/Jahr zur printMonth Methode hinzufügen.

so ändern, diesen Teil des Codes des printMonth Methode:

// 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); 
     } 
    } 

etwas wie folgt aus:

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); 
     } 
    } 
+0

Danke, es funktioniert . Jetzt möchte ich die Tage mit Ereignissen farblich gestalten. Ich habe versucht, JSON und PHP zu verwenden, aber es funktioniert nicht Ich habe meinen Post mit der Methode getJSON und dem PHP-Code aktualisiert. Ich hoffe, dass Sie mir helfen können –

Verwandte Themen