Matt23

Android weird behaviour

Jun 30th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public class DayOfWeek extends Fragment
  2. {
  3.     private View rootView;
  4.     private Switch toggle;
  5.  
  6.     @Override
  7.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  8.     {
  9.         rootView = inflater.inflate(R.layout.fragment_dayofweek, container, false);
  10.  
  11.         toggle = (Switch) rootView.findViewById(R.id.hint_switch);
  12.         toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
  13.         {
  14.             @Override
  15.             public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked)
  16.             {
  17.                 process();
  18.             }
  19.         });
  20.  
  21.         rootView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener()
  22.         {
  23.             @Override
  24.             public void onClick(View view)
  25.             {
  26.                 process();
  27.             }
  28.         });
  29.  
  30.         return rootView;
  31.     }
  32.  
  33.     private void process()
  34.     {
  35.         String day = ((EditText) rootView.findViewById(R.id.day)).getText().toString();
  36.         String month = ((EditText) rootView.findViewById(R.id.month)).getText().toString();
  37.         String year = ((EditText) rootView.findViewById(R.id.year)).getText().toString();
  38.  
  39.         if (!(Validator.isInteger(day) && Validator.isInteger(month) && Validator.isInteger(year))) {
  40.             displayWarning();
  41.             return;
  42.         }
  43.  
  44.         if (ba.isDateValid()) {
  45.  
  46.             TextView tv = (TextView) rootView.findViewById(R.id.textView);
  47.             tv.setText(result);
  48.             tv.setTextAlignment((toggle.isChecked() ? View.TEXT_ALIGNMENT_TEXT_START : View.TEXT_ALIGNMENT_CENTER));
  49.             Log.d("Toggle status", String.valueOf(toggle.isChecked()));
  50.             Log.d("Alignment", String.valueOf((toggle.isChecked() ? View.TEXT_ALIGNMENT_TEXT_START : View.TEXT_ALIGNMENT_CENTER)));
  51.  
  52.         }
  53.         else {
  54.             displayWarning();
  55.         }
  56.     }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment