Currently, I have three textviews (H M S) for hours, minutes, and seconds, respectively. They are selectable; however, let's say textView H is selected. when the textview M is touched then textview H automatically gets deselected and textview M is the only one selected. Same case for S. So they switch.
Right now I have the following:
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView previousText = (TextView) previousView;
TextView curText = (TextView) v;
// If the clicked view is selected, deselect it
if (curText.isSelected()) {
curText.setSelected(false);
curText.setTextColor(getResources().getColor(R.color.red_highlight));
}
// If this isn't selected, deselect the previous one (if any)
else {
if (previousText != null && previousText.isSelected()) {
previousText.setSelected(false);
previousText.setTextColor(getResources().getColor(R.color.red_highlight));
}
curText.setSelected(true);
curText.setTextColor(getResources().getColor(R.color.white));
previousView = v;
}
}
};
findViewById(R.id.hourtext).setOnClickListener(clickListener);
findViewById(R.id.minutetext).setOnClickListener(clickListener);
findViewById(R.id.secondtext).setOnClickListener(clickListener);
I want the timer to record for hours when H is selected, minutes when M is selected, and seconds when S is selected.
I am trying to follow this:
Android OnClickListener - identify a button
But how do I check which TextView is selected currently, so a different method/function can be performed when that TextView is selected.