Is there a way to get a specific date to be highlighted in a DatePicker controller in Android Studio?
My goal is that once the activity that contains the DatePicker is loaded, a few dates are already highlighted (Those that contain relevant data for the user), although not selected. Any way to get it?
I'm looking for something like this, the way to get specific dates with a dot below, as if there was a task on that specific date, but all the tutorials I've found are for javascript, css or html, nothing for Android.
(edited)
I'm trying to get it out on my own. What I have done is create a new php file that returns all the dates that a specific user has, and then collect that data in a JSONArray as shown below:
public void cogerFechas(){
String username = i.getStringExtra("us_usuario");
String password = i.getStringExtra("us_clave");
Response.Listener<String> responseListener = new Response.Listener<String>(){
@Override
public void onResponse(String response){
try {
JSONArray jsonArray = new JSONArray(response);
String fechaAux;
for(int x=0; x<jsonArray.length(); x++){
JSONObject jsonObject = jsonArray.getJSONObject(x);
fechaAux = jsonObject.getString("fecha");
arrayIntFechas = new ArrayList<>();
arrayIntFechas.add(separarFecha(fechaAux));
}
}catch(JSONException e){
AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
builder.setMessage(e.getMessage())
.setNegativeButton("Retry", null)
.create().show();
}catch(ArrayIndexOutOfBoundsException e){
AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
builder.setMessage("Error de excepción en el array "+e.getLocalizedMessage())
.setNegativeButton("Retry", null)
.create().show();
}
if(!arrayIntFechas.isEmpty()){
}else if(arrayIntFechas.isEmpty()){
}
}
};
FechasRequest fechasRequest = new FechasRequest(username, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(Usuario.this);
queue.add(fechasRequest);
}
I separate the dates into integers so that later the calendar can recognize them (Since the DatePicker component requires three integers to alter the year, month and day), but here I am, since I don't know what to do after the array is filled with all possible dates. My logic tells me that there should be some way to go through all the days in the calendar and highlight the dates that match the ones I got, but I have no idea how to do that.
Here is the code of the separateDate() method
public int[] separarFecha(String fecha){
String[] añoMesDia = fecha.split("-");
String añoS = añoMesDia[0], mesS = añoMesDia[1], diaS = añoMesDia[2];
int año = Integer.parseInt(añoS), mes = Integer.parseInt(mesS), dia =
Integer.parseInt(diaS);
int [] arrFecha = {año, mes, dia};
return arrFecha;
}
In the following link you can see how to do what I ask, although it cannot be done with a DatePicker component as I originally wanted.
Mark items in an Android calendar