I'm using 'Fragment' to obtain a layout with two 'fragments' so my class extends 'Fragment'.
I'm loading a 'ListView' on the left 'fragment' and on the right 'fragment' I have another modified 'ListView'. Here, I have a 'Spinner' that I have to change it's color.
I have this code:
private void loadSpinner(int value) {
//Not relevant code
adapter = new ArrayAdapter<CharSequence>(getActivity().getApplicationContext(), android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(R.layout.spinner);
spinner.setAdapter(adapter);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String value = parent.getItemAtPosition(position).toString();
((TextView) parent.getChildAt(0)).setTextColor(getResources().getColor(R.color.black));
//Some code
}
The code above is working as expected UNTIL I rotate the screen of my device. Here, I'm getting a nullpointerexception
at ((TextView) parent.getChildAt(0)).setTextColor(getResources().getColor(R.color.black));
.
If I comment the above line, since I'm saving the state before rotating the screen, after I rotate the screen, my data is restored and all works as expected EXCEPT the spinner that is on light color thus being poorly visible.
I understand that I can create my own 'spinner' layout and solve this matter but I would like to know how can I solve this.