List of usage examples for android.widget RadioButton setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:it.andreascarpino.forvodroid.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.settings, container, false); SharedPreferences preferences = getActivity().getSharedPreferences(MainActivity.CONFIG_FILE, Context.MODE_PRIVATE); EditText apiKey = (EditText) rootView.findViewById(R.id.api_key); String key = preferences.getString(MainActivity.CONFIG_API_KEY, ""); if (key.length() > 0) { apiKey.setText(key);//from w w w .j av a 2 s. c om } EditText languages = (EditText) rootView.findViewById(R.id.languages); String langs = preferences.getString(MainActivity.CONFIG_LANGUAGES, ""); if (langs.length() > 0) { languages.setText(langs); } // By default use OGG final RadioButton ogg = (RadioButton) rootView.findViewById(R.id.ogg); final RadioButton mp3 = (RadioButton) rootView.findViewById(R.id.mp3); ogg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mp3.setChecked(!isChecked); } }); mp3.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ogg.setChecked(!isChecked); } }); boolean oggEnabled = preferences.getBoolean(MainActivity.CONFIG_OGG, true); ogg.setChecked(oggEnabled); if (oggEnabled) { mp3.setChecked(false); } else { mp3.setChecked(true); } return rootView; }
From source file:com.nextgis.maplibui.dialog.LocalResourcesListAdapter.java
protected void setRadioButton(final RadioButton radioButton, final File file) { radioButton.setOnCheckedChangeListener(null); if (mCheckState.contains(file.getAbsolutePath())) { mUncheckBtn = radioButton;// w ww . ja v a2s . c om if (!radioButton.isChecked()) { radioButton.setChecked(true); } } else { if (radioButton.isChecked()) { radioButton.setChecked(false); } } radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { if (mCheckState.isEmpty()) { mCheckState.add(file.getAbsolutePath()); } else { mCheckState.set(0, file.getAbsolutePath()); } if (null != mUncheckBtn && mUncheckBtn != radioButton) { mUncheckBtn.setChecked(false); } mUncheckBtn = radioButton; } mDialog.updateButtons(); } }); }
From source file:com.bonsai.wallet32.SweepKeyActivity.java
private void addAccountRow(TableLayout table, int acctId, String acctName, long btc, double fiat) { TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.receive_to_row, table, false); RadioButton tv0 = (RadioButton) row.findViewById(R.id.to_account); tv0.setId(acctId); // Change id to the acctId. tv0.setText(acctName);//ww w .j a v a2 s . c om tv0.setOnCheckedChangeListener(mReceiveToListener); if (acctId == mAccountId) tv0.setChecked(true); TextView tv1 = (TextView) row.findViewById(R.id.row_btc); tv1.setText(String.format("%s", mBTCFmt.formatCol(btc, 0, true, true))); TextView tv2 = (TextView) row.findViewById(R.id.row_fiat); tv2.setText(String.format("%.02f", fiat)); table.addView(row); }
From source file:com.vuze.android.remote.dialog.DialogFragmentRcmAuth.java
@Override public void onResume() { super.onResume(); AlertDialog d = (AlertDialog) getDialog(); if (d != null) { final Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); final RadioButton rbPre = (RadioButton) d.findViewById(R.id.rcm_rb_pre); final RadioButton rbAll = (RadioButton) d.findViewById(R.id.rcm_rb_all); all = rbAll.isChecked();/*from ww w .ja va 2s.c om*/ positiveButton.setEnabled(rbPre.isChecked() || rbAll.isChecked()); OnCheckedChangeListener l = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { positiveButton.setEnabled(rbPre.isChecked() || rbAll.isChecked()); all = rbAll.isChecked(); } }; rbPre.setOnCheckedChangeListener(l); rbAll.setOnCheckedChangeListener(l); } }
From source file:com.RSMSA.policeApp.Adapters.ViewPagerAccidentsDetailsAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); android.widget.ScrollView itemView = (ScrollView) inflater.inflate(R.layout.accident_details, container, false);/* www. ja v a 2s.c om*/ final AccidentVehicle accidentVehicle = new AccidentVehicle(); Button addPasenger = (Button) itemView.findViewById(R.id.add_witness); Button next = (Button) itemView.findViewById(R.id.next); final LinearLayout linearLayout = (LinearLayout) itemView.findViewById(R.id.passengers_layout); if (position == tabnames.size() - 1) { next.setVisibility(View.VISIBLE); } else { next.setVisibility(View.GONE); } next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AccidentReportFormActivity.showWitneses(); } }); final EditText fatalEdit = (EditText) itemView.findViewById(R.id.fatal_edit); fatalEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setFatal")); final EditText simpleEdit = (EditText) itemView.findViewById(R.id.simple_edit); simpleEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setSimple")); EditText injuryEdit = (EditText) itemView.findViewById(R.id.injury_edit); injuryEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setSevere_injured")); EditText notInjuredEdit = (EditText) itemView.findViewById(R.id.not_injured_edit); notInjuredEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setOnly_damage")); EditText driverLicenceEdit = (EditText) itemView.findViewById(R.id.license_one); driverLicenceEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setLicence_no") { public void afterFocus(final String text, final EditText editText) { new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... params) { DHIS2Modal dhis2Modal = new DHIS2Modal("Driver", null, MainOffence.username, MainOffence.password); JSONObject where = new JSONObject(); try { where.put("value", text); } catch (JSONException e) { e.printStackTrace(); } JSONObject driverObject = null; try { JSONArray driver = dhis2Modal.getEvent(where); Log.d(TAG, "returned driver json = " + driver.toString()); driverObject = driver.getJSONObject(0); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } try { if (driverObject.getString("Driver License Number").equals(text)) { accidentVehicle.setProgram_driver(driverObject.getString("id")); return true; } } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { Log.e(TAG, "returned json object is null"); } return false; } @Override protected void onPostExecute(Boolean aVoid) { super.onPostExecute(aVoid); if (!aVoid) { editText.setTextColor(context.getResources().getColor(R.color.red)); } else { editText.setTextColor(context.getResources().getColor(R.color.green_500)); } } }.execute(); } }); final EditText alcoholEdit = (EditText) itemView.findViewById(R.id.alcohol_edit); alcoholEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setAlcohol_percentage")); CheckBox drug = (CheckBox) itemView.findViewById(R.id.drug_edit); drug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { accidentVehicle.setDrug(isChecked); } }); CheckBox phone = (CheckBox) itemView.findViewById(R.id.phone_edit); phone.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { accidentVehicle.setPhone_use(isChecked); } }); EditText plateNumber = (EditText) itemView.findViewById(R.id.registration_number_one); plateNumber.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setPlate_number") { public void afterFocus(final String text, final EditText editText) { new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... params) { DHIS2Modal dhis2Modal = new DHIS2Modal("Vehicle", null, MainOffence.username, MainOffence.password); JSONObject where = new JSONObject(); try { where.put("value", text); } catch (JSONException e) { e.printStackTrace(); } JSONObject vehicleObject = null; try { JSONArray vehiclesArray = dhis2Modal.getEvent(where); Log.d(TAG, "returned vehicle json = " + vehiclesArray.toString()); vehicleObject = vehiclesArray.getJSONObject(0); } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } try { if (vehicleObject.getString("Vehicle Plate Number").equals(text)) { accidentVehicle.setProgram_vehicle(vehicleObject.getString("id")); return true; } } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { Log.e(TAG, "returned json object is null"); } return false; } @Override protected void onPostExecute(Boolean aVoid) { super.onPostExecute(aVoid); if (!aVoid) { editText.setTextColor(context.getResources().getColor(R.color.red)); } else { editText.setTextColor(context.getResources().getColor(R.color.light_gray)); } } }.execute(); } }); EditText repairCost = (EditText) itemView.findViewById(R.id.repair_amount_one); repairCost.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setEstimated_repair")); EditText vehicleEdit = (EditText) itemView.findViewById(R.id.vehicle_title_edit); vehicleEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setVehicle")); EditText vehicleTotalEdit = (EditText) itemView.findViewById(R.id.vehicle_total_edit); vehicleTotalEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setVehicle_total")); EditText infastructureEdit = (EditText) itemView.findViewById(R.id.infrastructure_edit); infastructureEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setInfastructure")); EditText costEdit = (EditText) itemView.findViewById(R.id.rescue_cost_edit); costEdit.setOnFocusChangeListener(new CustomeTimeWatcher(accidentVehicle, "setCost")); final List<PassengerVehicle> passengers = new ArrayList<PassengerVehicle>(); addPasenger.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PassengerVehicle passengerVehicle = new PassengerVehicle(); LinearLayout passenger = (LinearLayout) inflater.inflate(R.layout.passenger, null); linearLayout.addView(passenger); EditText nameEdit = (EditText) passenger.findViewById(R.id.name_edit); nameEdit.setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setName")); final EditText dateOfBirth = (EditText) passenger.findViewById(R.id.dob_one); dateOfBirth.setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setDate_of_birth")); EditText physicalAddressEdit = (EditText) passenger.findViewById(R.id.physical_address_one); physicalAddressEdit .setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setPhysical_address")); EditText addressBoxEdit = (EditText) passenger.findViewById(R.id.address_box_one); addressBoxEdit.setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setAddress")); EditText nationalIDEdit = (EditText) passenger.findViewById(R.id.national_id_one); nationalIDEdit.setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setNational_id")); EditText phoneNoEdit = (EditText) passenger.findViewById(R.id.phone_no_one); phoneNoEdit.setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setPhone_no")); EditText alcoholPercentageEdit = (EditText) passenger.findViewById(R.id.alcohol_percentage); alcoholPercentageEdit .setOnFocusChangeListener(new CustomeTimeWatcher(passengerVehicle, "setAlcohol_percent")); CheckBox seatbeltCheckbox = (CheckBox) passenger.findViewById(R.id.seat_belt_check); seatbeltCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { passengerVehicle.setHelmet(isChecked); } }); Button date_picker = (Button) passenger.findViewById(R.id.date_picker); date_picker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DatePickerDialog newDatePickerDialogueFragment; newDatePickerDialogueFragment = new DatePickerDialog(); newDatePickerDialogueFragment.show(AccidentReportFormActivity.fragmentManager, "DatePickerDialogue"); newDatePickerDialogueFragment .setOnDateSetListener(new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { dateOfBirth.setText(dayOfMonth + " / " + (monthOfYear + 1) + " / " + year); } }); } }); final RadioButton male = (RadioButton) passenger.findViewById(R.id.male); male.setTypeface(MainOffence.Roboto_Regular); final RadioButton female = (RadioButton) passenger.findViewById(R.id.female); female.setTypeface(MainOffence.Roboto_Regular); passengerVehicle.setGender("Male"); male.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) passengerVehicle.setGender("Male"); } }); female.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) passengerVehicle.setGender("Female"); } }); passengers.add(linearLayout.getChildCount() - 1, passengerVehicle); } }); accident[position] = accidentVehicle; passanger.add(position, passengers); ((ViewPager) container).addView(itemView); return itemView; }
From source file:com.bonsai.wallet32.SendBitcoinActivity.java
private void addAccountRow(TableLayout table, int acctId, String acctName, long btc, double fiat) { TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.send_from_row, table, false); RadioButton tv0 = (RadioButton) row.findViewById(R.id.from_account); tv0.setId(acctId); // Change id to the acctId. tv0.setText(acctName);/*from ww w . j a v a 2 s. com*/ tv0.setOnCheckedChangeListener(mSendFromListener); if (acctId == mCheckedFromId) tv0.setChecked(true); TextView tv1 = (TextView) row.findViewById(R.id.row_btc); tv1.setText(String.format("%s", mBTCFmt.formatCol(btc, 0, true, true))); TextView tv2 = (TextView) row.findViewById(R.id.row_fiat); tv2.setText(String.format("%.02f", fiat)); table.addView(row); }
From source file:com.frostwire.android.gui.fragments.BrowsePeerFragment.java
private RadioButton initRadioButton(View v, int viewId, final byte fileType) { RadioButton button = findView(v, viewId); Resources r = button.getResources(); FileTypeRadioButtonSelectorFactory fileTypeRadioButtonSelectorFactory = new FileTypeRadioButtonSelectorFactory( fileType, r, FileTypeRadioButtonSelectorFactory.RadioButtonContainerType.BROWSE); fileTypeRadioButtonSelectorFactory.updateButtonBackground(button); button.setClickable(true);/* ww w .j ava2s.c o m*/ RadioButtonListener rbListener = new RadioButtonListener(button, fileType, fileTypeRadioButtonSelectorFactory); button.setOnClickListener(rbListener); button.setOnCheckedChangeListener(rbListener); button.setChecked(fileType == Constants.FILE_TYPE_AUDIO); radioButtonFileTypeMap.put(fileType, button); return button; }
From source file:com.RSMSA.policeApp.Fragments.PaymentVerifierFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { contentView = (RelativeLayout) inflater.inflate(R.layout.fragment_payment_verifier, container, false); /**//from ww w .j a v a 2 s.c o m * get the instances of the buttons at our view */ progressBar = (ProgressBar) contentView.findViewById(R.id.pbar_main); inputnformation = (RelativeLayout) contentView.findViewById(R.id.input_information); verificationResults = (ScrollView) contentView.findViewById(R.id.verification_results); driversOffenceList = (LinearLayout) contentView.findViewById(R.id.history_list_driver); vehiclesOffenceList = (LinearLayout) contentView.findViewById(R.id.history_list_car); vehiclesDetails = (LinearLayout) contentView.findViewById(R.id.vehicles_details); driversDetails = (LinearLayout) contentView.findViewById(R.id.drivers_details); nameTextView = (TextView) contentView.findViewById(R.id.name); licenseNumberTextView = (TextView) contentView.findViewById(R.id.license_number); addressTextView = (TextView) contentView.findViewById(R.id.address); genderTextView = (TextView) contentView.findViewById(R.id.gender); dateOfBirthTextView = (TextView) contentView.findViewById(R.id.date_of_birth); phoneNumberTextView = (TextView) contentView.findViewById(R.id.phone_number); makeTextView = (TextView) contentView.findViewById(R.id.make); plateNumberTextView = (TextView) contentView.findViewById(R.id.plate_number); typeTextView = (TextView) contentView.findViewById(R.id.type); colorTextView = (TextView) contentView.findViewById(R.id.color); scanBtn = (ImageView) contentView.findViewById(R.id.scan_button); verifyBtn = (Button) contentView.findViewById(R.id.verify); verifyBtn.setTypeface(MainOffence.Rosario_Bold); licenseEdittext = (EditText) contentView.findViewById(R.id.license_); verifyBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d("MainOffense", "verify button clicked"); licenceNumber = licenseEdittext.getText().toString(); if (licenceNumber.equals("")) { Toast toast = Toast.makeText(getActivity(), " Field Empty!", Toast.LENGTH_SHORT); toast.show(); } else { verifyBtn.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); progressBar.bringToFront(); NetAsync(view); } } }); final RadioButton licence = (RadioButton) contentView.findViewById(R.id.licence); licence.setTypeface(MainOffence.Roboto_Regular); final RadioButton plate = (RadioButton) contentView.findViewById(R.id.plate); plate.setTypeface(MainOffence.Roboto_Regular); licence.setChecked(true); licence.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { driversPaymentVerification = true; licenseEdittext.setHint("Enter Licence No"); } } }); plate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { driversPaymentVerification = false; licenseEdittext.setHint("Enter Plate No"); } } }); try { receivedNumber = getArguments().getString("licenceNumber"); } catch (Exception e) { } if (receivedNumber != null) { verifyLicenceNumber(receivedNumber); } else { try { receivedNumber = getArguments().getString("plateNumber"); } catch (Exception e) { } if (!receivedNumber.equals("") || receivedNumber != null) { driversPaymentVerification = false; plate.setChecked(true); licence.setChecked(false); verifyLicenceNumber(receivedNumber); } } return contentView; }
From source file:com.markupartist.sthlmtraveling.PlannerFragment.java
public void initViews() { mSearchView = getActivity().getLayoutInflater().inflate(R.layout.search, null); getListView().addHeaderView(mSearchView, null, false); final TextView historyView = (TextView) getActivity().getLayoutInflater().inflate(R.layout.header, null); historyView.setText(R.string.history_label); historyView.setOnClickListener(null); // Makes the header un-clickable, hack! getListView().addHeaderView(historyView); // Hide dividers on the header view. getListView().setHeaderDividersEnabled(false); if (!mStartPoint.hasName()) { mStartPoint.setName(Site.TYPE_MY_LOCATION); }/*from ww w . ja v a 2 s .c o m*/ mStartPointAutoComplete = createAutoCompleteTextView(R.id.from, /*R.id.from_progress*/ -1, mStartPoint); mEndPointAutoComplete = createAutoCompleteTextView(R.id.to, /*R.id.to_progress*/ -1, mEndPoint); mViaPointAutoComplete = createAutoCompleteTextView(R.id.via, /*R.id.via_progress*/ -1, mViaPoint, true); try { mHistoryDbAdapter = new HistoryDbAdapter(getActivity()).open(); } catch (final Exception e) { showDialog(createDialogReinstallApp()); return; } // Setup view for choosing other data for start and end point. final ImageButton fromDialog = (ImageButton) mSearchView.findViewById(R.id.from_menu); fromDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mStartPointAutoComplete.setError(null); showDialog(createDialogStartPoint()); } }); final ImageButton toDialog = (ImageButton) mSearchView.findViewById(R.id.to_menu); toDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mEndPointAutoComplete.setError(null); showDialog(createDialogEndPoint()); } }); final ImageButton viaDialog = (ImageButton) mSearchView.findViewById(R.id.via_menu); viaDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mViaPointAutoComplete.setError(null); showDialog(createDialogViaPoint()); } }); // Views for date and time mChangeTimeLayout = (LinearLayout) mSearchView.findViewById(R.id.planner_change_time_layout); mDateButton = (Button) mSearchView.findViewById(R.id.planner_route_date); mDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { showDialog(createDialogDate()); } }); mTimeButton = (Button) mSearchView.findViewById(R.id.planner_route_time); mTimeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { showDialog(createDialogTime()); } }); // Views for radio buttons final RadioButton nowRadioButton = (RadioButton) mSearchView.findViewById(R.id.planner_check_now); nowRadioButton.setOnCheckedChangeListener(this); final RadioButton laterRadioButton = (RadioButton) mSearchView .findViewById(R.id.planner_check_more_choices); laterRadioButton.setOnCheckedChangeListener(this); mWhenSpinner = (Spinner) mSearchView.findViewById(R.id.departure_arrival_choice); final ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.when_choice, android.R.layout.simple_spinner_item); whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWhenSpinner.setAdapter(whenChoiceAdapter); // Handle create shortcut. if (mCreateShortcut) { registerScreen("Planner create shortcut"); getActivity().setTitle(R.string.create_shortcut_label); // Add search label to button RadioGroup chooseTimeGroup = (RadioGroup) mSearchView.findViewById(R.id.planner_choose_time_group); chooseTimeGroup.setVisibility(View.GONE); historyView.setVisibility(View.GONE); // Fake an adapter. This needs to be fixed later on so we can use the history. setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.journey_history_row)); } else { setListAdapter(mAdapter); } }
From source file:com.RSMSA.policeApp.OffenceReportForm.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_report_offence); sharedpreferences = getSharedPreferences(MyPREF, Context.MODE_PRIVATE); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . ja va 2s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); } SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.blue_900)); tintManager.setTintDrawable(colorDrawable); RelativeLayout inputs = (RelativeLayout) findViewById(R.id.inputs); plateNumberEdit = (EditText) findViewById(R.id.plate_number_edit_text); licenceNumberEdit = (EditText) findViewById(R.id.licence_number_edit_text); final Bundle bundle = getIntent().getExtras(); namePassed = bundle.getString("name"); dLicense = bundle.getString("licence_number"); plateNumberObtained = bundle.getString("plate_number"); driverUid = bundle.getString("driverUid"); vehicleUid = bundle.getString("vehicleUid"); try { invalidLicence = bundle.getString("invalidLicence"); expiredInsuarance = bundle.getString("expiredInsuarance"); } catch (NullPointerException e) { } if (dLicense.equals("") || dLicense == null) { licenceNumberEdit.setVisibility(View.VISIBLE); } else if (plateNumberObtained.equals("") || plateNumberObtained == null) { plateNumberEdit.setVisibility(View.VISIBLE); } submit = (TextView) findViewById(R.id.submit_text); plateNo = (TextView) findViewById(R.id.plate_no_); chargesAcceptance = (TextView) findViewById(R.id.charges_acceptance); chargesAcceptance.setTypeface(MainOffence.Roboto_Regular); offensesCommittedTextview = (TextView) findViewById(R.id.offences_committed_title); offensesCommittedTextview.setTypeface(MainOffence.Roboto_BoldCondensed); ChargesAcceptanceTitle = (TextView) findViewById(R.id.charges_acceptance_title); paymentMethodTitle = (TextView) findViewById(R.id.payment_method_title); PaymentTitle = (TextView) findViewById(R.id.payment_title); ChargesAcceptanceTitle.setTypeface(MainOffence.Roboto_BoldCondensed); paymentMethodTitle.setTypeface(MainOffence.Roboto_BoldCondensed); PaymentTitle.setTypeface(MainOffence.Roboto_BoldCondensed); offencesCostTitle = (TextView) findViewById(R.id.offences_cost_title); offencesCostTitle.setTypeface(MainOffence.Roboto_BoldCondensed); submitText = (TextView) findViewById(R.id.submit_text); license = (TextView) findViewById(R.id.license); license.setText(dLicense); report = (RelativeLayout) findViewById(R.id.report); summary = (RelativeLayout) findViewById(R.id.summary); submit_layout = (RelativeLayout) findViewById(R.id.submit_layout); submit_layout1 = (RelativeLayout) findViewById(R.id.submit_layout1); submit_layout1.setVisibility(View.GONE); progressBar = (ProgressBar) findViewById(R.id.pbar_report); TextView driverName = (TextView) findViewById(R.id.driver_name); driverName.setTypeface(MainOffence.Roboto_BoldCondensed); TextView plateNumberTitle = (TextView) findViewById(R.id.plate_no_title_); plateNumberTitle.setTypeface(MainOffence.Roboto_BoldCondensed); TextView driverLicense = (TextView) findViewById(R.id.driver_license); driverLicense.setTypeface(MainOffence.Roboto_BoldCondensed); RelativeLayout OffenseType = (RelativeLayout) findViewById(R.id.offense_type); OffenseType.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(OffenceReportForm.this, OffenseListActivity.class); OffenceReportForm.this.startActivityForResult(intent, REPORT_RESULT); } }); offense_type_text = (TextView) findViewById(R.id.offense_type_text); offencesSelectedTextView = (TextView) findViewById(R.id.offence_list); offensesCommittedTextview = (TextView) findViewById(R.id.offences_committed); TextView name = (TextView) findViewById(R.id.name); name.setText(namePassed); final RadioButton court = (RadioButton) findViewById(R.id.court); court.setTypeface(MainOffence.Roboto_BoldCondensed); final RadioButton guilty = (RadioButton) findViewById(R.id.guilty); guilty.setTypeface(MainOffence.Roboto_BoldCondensed); guilty.setChecked(true); court.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { guilty.setChecked(false); commit = false; } } }); guilty.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { court.setChecked(false); commit = true; } } }); final String[] paymentMethodsArray = this.getResources().getStringArray(R.array.payment_methods); final Spinner paymentMethodSpinner = (Spinner) findViewById(R.id.payment_method_spinner); final RadioButton paid = (RadioButton) findViewById(R.id.paid); paid.setTypeface(MainOffence.Roboto_Regular); final RadioButton not_paid = (RadioButton) findViewById(R.id.not_paid); final TextView receipt_title = (TextView) findViewById(R.id.receipt_title); receiptEditText = (EditText) findViewById(R.id.receipt); receipt_title.setTypeface(MainOffence.Roboto_BoldCondensed); not_paid.setTypeface(MainOffence.Roboto_Regular); not_paid.setChecked(true); paymentMethodSpinner.setBackground(null); paid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { paymentStatus = true; paymentMethodTitle.setVisibility(View.VISIBLE); paymentMethodSpinner.setVisibility(View.VISIBLE); paymentMethod = paymentMethodsArray[0]; paymentMethodSpinner.setSelection(0); receipt_title.setVisibility(View.VISIBLE); receiptEditText.setVisibility(View.VISIBLE); } } }); not_paid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b == true) { paymentStatus = false; paymentMethodTitle.setVisibility(View.GONE); paymentMethodSpinner.setVisibility(View.GONE); receipt_title.setVisibility(View.GONE); receiptEditText.setVisibility(View.GONE); paymentMethod = ""; receiptEditText.setText(""); } } }); PaymentMethodSpinnerAdapter adapter = new PaymentMethodSpinnerAdapter( getSupportActionBar().getThemedContext(), R.layout.row_menu, paymentMethodsArray); paymentMethodSpinner.setAdapter(adapter); paymentMethodSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { paymentMethod = paymentMethodsArray[position]; if (position == 0) { receiptEditText.setVisibility(View.VISIBLE); receipt_title.setVisibility(View.VISIBLE); } else { receiptEditText.setVisibility(View.GONE); receipt_title.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }