0
I have the following code:
String[] hours = new String[]{
"0:00 da madrugada",
"0:30 da madrugada",
"1:00 da madrugada",
"1:30 da madrugada",
"2:00 da madrugada",
"2:30 da madrugada",
"3:00 da madrugada",
"3:30 da madrugada",
"4:00 da madrugada",
"4:30 da madrugada",
"5:00 da madrugada",
"5:30 da madrugada",
"6:00 da manhã",
"6:30 da manhã",
"7:00 da manhã",
"7:30 da manhã",
"8:00 da manhã",
"8:30 da manhã",
"9:00 da manhã",
"9:30 da manhã",
"10:00 da manhã",
"10:30 da manhã",
"11:00 da manhã",
"11:30 da manhã",
"12:00 da tarde",
"12:30 da tarde",
"13:00 da tarde",
"13:30 da tarde",
"14:00 da tarde",
"14:30 da tarde",
"15:00 da tarde",
"15:30 da tarde",
"16:00 da tarde",
"16:30 da tarde",
"17:00 da tarde",
"17:30 da tarde",
"18:00 da noite",
"18:30 da noite",
"19:00 da noite",
"19:30 da noite",
"20:00 da noite",
"20:30 da noite",
"21:00 da noite",
"21:30 da noite",
"22:00 da noite",
"22:30 da noite",
"23:00 da noite",
"23:30 da noite"
};
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void alertDialogStartHour(){
AlertDialog.Builder alertdialog = new AlertDialog.Builder(getContext());
@SuppressLint("InflateParams") final View viewDialog = getLayoutInflater()
.inflate(R.layout.alertdialog_horas,null);
final AlertDialog dialog = alertdialog.create();
dialog.setCancelable(true);
final ListView listView = viewDialog.findViewById(R.id.listViewHoras);
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(getContext()),
android.R.layout.simple_list_item_1, android.R.id.text1, hours);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startHour = position;
String itemValue = (String) listView.getItemAtPosition(position);
textView_Hour.setText(itemValue);
dialog.dismiss();
}
});
dialog.setView(viewDialog);
dialog.show();
}
My intention is to be able to manipulate the color of my own free will. This is because, depending on the time of day, as an example (12:00 pm), the texts with previous times and that present in black, stay in the color red, indicating to the user that it is not allowed to select that time if the same is clicked.
You have to write an Adapter.
– ramaral
Yeah, I guess that’s the way.....
– André alas
No need friend.... You can change dynamically. See the solution found by me in the answer...
– André alas
Friend, what you did was nothing more than write an Adapter, as I suggested in my comment. You just did it anonymously( Anonymous class).
– ramaral
Yeah, but you didn’t explain what kind of Adapter I had to do or how to.... kkkkkk I mean, to me his reply gave the intender that the Adapter that I had to do is a custom Adapter using a custom layout.
– André alas