There is a similar question on SO but i reckon my problem lies elsewhere or I’m missing something rather fundamental here.
I do have a unique ID set for my dialog : static final int DAYS_DIALOG_ID = 1;
I also have a class member variable : private TextView textViewSelectDayOfWeek;
In my overriden method onCreate(), i have :
textViewSelectDayOfWeek = (TextView) findViewById(R.id.textViewSelectDayOfWeek);
textViewSelectDayOfWeek.setOnClickListener(this);
So basically, i caputre my TextView defined in XML file in a variable and i set it’s listener.
In my onClick(view v), there’s a switch with the following case that is supposed to handle clicks on the TextView that is supposed to handle opening my dialog (do note that the aforementioned switch uses v.getId()):
case R.id.textViewSelectDayOfWeek:
showDialog(DAYS_DIALOG_ID);
break;
My overriden method onCreateDialog(int id) also contains a switch statement that uses the ID provided. The case that handles this particular problem-causing dialog is the following:
case DAYS_DIALOG_ID:
final CharSequence[] daysOfWeek = { "@string/stringMonday"}; // 7 days, skimming unimportant stuff
return new AlertDialog.Builder(this)
.setTitle("@string/stringSelectDayDialogTitle")
.setMultiChoiceItems(daysOfWeek,
new boolean[] {true, true, true, true, true}, // Sets first 5 days as checked by default
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int day, boolean isChecked) {
Toast.makeText(getApplicationContext(), daysOfWeek[day], Toast.LENGTH_SHORT).show();
}
})
.create();
Now, if i click on the TextView with ID textViewSelectDayOfWeek, my app crashes.
I tried Toasting a message in onClick() right before i call showDialog(DAYS_DIALOG_ID) and the message does NOT appear before my app crashes.
What can i do to fix this problem ? I believe i mentioned all the important bits of my code but feel encouraged to request anything that might help.
Thanks in advance.
I certainly hope this helps someone.
As thinksteep mentioned, the exception thrown is actually fairly useful 🙂
I had an array of 7 week days and i supplied an incomplete array containing only 5 boolean values, which were to define whether the day is checked or unchecked by default, thinking the remaining values would be initialized with a default value of some kind.