I am using the spinner for showing the value as dropdown, I am changing the spinner text value by using below code
<Spinner
android:id="@+id/showUnit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:entries="@array/unitName"
android:background="@drawable/gradient_spinner_map_miles_button" />
showUnit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String item = arg0.getItemAtPosition(arg2).toString();
if (arg1 != null && arg1 instanceof TextView) {
((TextView)arg1).setTextColor(Color.WHITE);
((TextView) arg1).setTextSize(13);
((TextView) arg1).setGravity(Gravity.CENTER);
}
}
showUnit = (Spinner) findViewById(R.id.showUnit);
But when I try to rotate the screen, ((TextView)arg0.getChildAt(0))
returns null.
I know that when I rotate the screen in landsacpe or portrait mode activity cycle is restart then why spinner is getting null.
Please give me appropriate solution.
Thanks