List of usage examples for android.widget RadioGroup setOnCheckedChangeListener
public void setOnCheckedChangeListener(OnCheckedChangeListener listener)
Register a callback to be invoked when the checked radio button changes in this group.
From source file:com.ultrafunk.network_info.config.ConfigActivity.java
private void initShowWidgetView() { RadioGroup showWidgetRadioGroup = (RadioGroup) findViewById(R.id.showWidgetRadioGroup); if (widgetConfig.showBothWidgets()) showWidgetRadioGroup.check(R.id.showBothRadioButton); else if (widgetConfig.showMobileDataWidget()) showWidgetRadioGroup.check(R.id.showMobileRadioButton); else// w w w . ja va2 s .co m showWidgetRadioGroup.check(R.id.showWifiRadioButton); showWidgetRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { RelativeLayout mobileSettingsScreenRelativeLayout = (RelativeLayout) findViewById( R.id.mobileSettingsScreenRelativeLayout); widgetConfig.setBothWidgets(false); if (checkedId == R.id.showBothRadioButton) { widgetConfig.setBothWidgets(true); mobileSettingsScreenRelativeLayout.setVisibility(View.VISIBLE); } if (checkedId == R.id.showMobileRadioButton) { widgetConfig.setMobileDataWidget(true); mobileSettingsScreenRelativeLayout.setVisibility(View.VISIBLE); } if (checkedId == R.id.showWifiRadioButton) { widgetConfig.setWifiWidget(true); mobileSettingsScreenRelativeLayout.setVisibility(View.GONE); } } }); }
From source file:eu.geopaparazzi.library.core.dialogs.ColorStrokeDialogFragment.java
@Override public Dialog onCreateDialog(Bundle bundle) { // create the dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View colorStrokeDialogView = getActivity().getLayoutInflater() .inflate(R.layout.fragment_dialog_color_stroke, null); builder.setView(colorStrokeDialogView); // add GUI to dialog /*/*from w w w .ja v a2s . c om*/ * the shape size image */ if (!mCurrentColorStrokeObject.hasShape) { View shapeSizeView = colorStrokeDialogView.findViewById(R.id.shapeSizeDialogGridLayout); shapeSizeView.setVisibility(View.GONE); } else { // mShapeSizeImageView = (ImageView) colorStrokeDialogView.findViewById(R.id.shapeSizeImageView); mShapeSizeTextView = (TextView) colorStrokeDialogView.findViewById(R.id.shapeSizeTextView); mShapeSizeSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.shapeSizeSeekBar); mShapeSizeSeekBar.setOnSeekBarChangeListener(shapeSizeChanged); mShapeSizeSeekBar.setProgress(mCurrentColorStrokeObject.shapeSize); mShapeSizeTextView.setText(String.valueOf(mCurrentColorStrokeObject.shapeSize)); mShapeSpinner = (Spinner) colorStrokeDialogView.findViewById(R.id.shape_spinner); int count = mShapeSpinner.getCount(); for (int i = 0; i < count; i++) { if (mShapeSpinner.getItemAtPosition(i).equals(mCurrentColorStrokeObject.shapeWKT)) { mShapeSpinner.setSelection(i); break; } } mShapeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Object selectedItem = mShapeSpinner.getSelectedItem(); String shapeStr = selectedItem.toString(); mCurrentColorStrokeObject.shapeWKT = shapeStr; } public void onNothingSelected(AdapterView<?> arg0) { // ignore } }); } /* * the stroke width image */ if (!mCurrentColorStrokeObject.hasStrokeWidth) { View lineWidthView = colorStrokeDialogView.findViewById(R.id.lineWidthDialogGridLayout); lineWidthView.setVisibility(View.GONE); } else { mWidthImageView = (ImageView) colorStrokeDialogView.findViewById(R.id.widthImageView); mWidthTextView = (TextView) colorStrokeDialogView.findViewById(R.id.widthTextView); mWidthSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.widthSeekBar); mWidthSeekBar.setOnSeekBarChangeListener(lineWidthChanged); mWidthSeekBar.setProgress(mCurrentColorStrokeObject.strokeWidth); mWidthTextView.setText(String.valueOf(mCurrentColorStrokeObject.strokeWidth)); } RadioButton fillRadioButton = (RadioButton) colorStrokeDialogView.findViewById(R.id.doFillRadioButton); fillRadioButton.setChecked(true); RadioGroup radioGroup = (RadioGroup) colorStrokeDialogView.findViewById(R.id.radioDo); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { onRadioButtonClicked(checkedId); } }); /* * The fill/stroke color picker part */ TextView title2 = (TextView) colorStrokeDialogView.findViewById(R.id.title2); if (!mCurrentColorStrokeObject.hasFill && !mCurrentColorStrokeObject.hasStroke) { View colorView = colorStrokeDialogView.findViewById(R.id.colorDialogGridLayout); colorView.setVisibility(View.GONE); } else { if (!mCurrentColorStrokeObject.hasFill || !mCurrentColorStrokeObject.hasStroke) { View radioView = colorStrokeDialogView.findViewById(R.id.radioDoLayout); radioView.setVisibility(View.GONE); } handlingFillColor = mCurrentColorStrokeObject.hasFill; String title = ""; if (mCurrentColorStrokeObject.hasFill && mCurrentColorStrokeObject.hasStroke) { title = getActivity().getString(R.string.fill_and_stroke_color_title); } else if (mCurrentColorStrokeObject.hasFill) { title = getActivity().getString(R.string.fill_color_title); } else { title = getActivity().getString(R.string.stroke_color_title); } title2.setText(title); // get the color SeekBars and set their onChange listeners mAlphaSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.alphaSeekBar); mRedSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.redSeekBar); mGreenSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.greenSeekBar); mBlueSeekBar = (SeekBar) colorStrokeDialogView.findViewById(R.id.blueSeekBar); mColorView = colorStrokeDialogView.findViewById(R.id.colorView); // register SeekBar event listeners mAlphaSeekBar.setOnSeekBarChangeListener(colorChangedListener); mRedSeekBar.setOnSeekBarChangeListener(colorChangedListener); mGreenSeekBar.setOnSeekBarChangeListener(colorChangedListener); mBlueSeekBar.setOnSeekBarChangeListener(colorChangedListener); int color = 0; int alpha = 0; if (handlingFillColor) { color = mCurrentColorStrokeObject.fillColor; alpha = mCurrentColorStrokeObject.fillAlpha; } else { color = mCurrentColorStrokeObject.strokeColor; alpha = mCurrentColorStrokeObject.strokeAlpha; } // use current drawing color to set SeekBar values mAlphaSeekBar.setProgress(alpha); mRedSeekBar.setProgress(Color.red(color)); mGreenSeekBar.setProgress(Color.green(color)); mBlueSeekBar.setProgress(Color.blue(color)); final ColorUtilities[] availableColors = ColorUtilities.values(); GridView gridview = (GridView) colorStrokeDialogView.findViewById(R.id.availableColors); ArrayAdapter<ColorUtilities> colorsAdapter = new ArrayAdapter<ColorUtilities>(getActivity(), android.R.layout.simple_list_item_1, availableColors) { class ViewHolder { Button button; } @Override public View getView(final int position, View cView, ViewGroup parent) { ViewHolder holder; View rowView = cView; if (rowView == null) { LayoutInflater inflater = getActivity().getLayoutInflater(); rowView = inflater.inflate(R.layout.fragment_dialog_color_stroke_row, parent, false); holder = new ViewHolder(); holder.button = (Button) rowView.findViewById(R.id.button); rowView.setTag(holder); } else { holder = (ViewHolder) rowView.getTag(); } String hex = availableColors[position].getHex(); int color = ColorUtilities.toColor(hex); holder.button.setBackgroundColor(color); final Button b = holder.button; holder.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int color = Color.TRANSPARENT; Drawable background = b.getBackground(); if (background instanceof ColorDrawable) color = ((ColorDrawable) background).getColor(); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); int argb = Color.argb(red, green, blue, mAlphaSeekBar.getProgress()); mColorView.setBackgroundColor(argb); mRedSeekBar.setProgress(red); mGreenSeekBar.setProgress(green); mBlueSeekBar.setProgress(blue); if (handlingFillColor) { mCurrentColorStrokeObject.fillColor = Color.rgb(mRedSeekBar.getProgress(), mGreenSeekBar.getProgress(), mBlueSeekBar.getProgress()); mCurrentColorStrokeObject.fillAlpha = mAlphaSeekBar.getProgress(); } else { mCurrentColorStrokeObject.strokeColor = Color.rgb(mRedSeekBar.getProgress(), mGreenSeekBar.getProgress(), mBlueSeekBar.getProgress()); mCurrentColorStrokeObject.strokeAlpha = mAlphaSeekBar.getProgress(); } } }); return rowView; } }; gridview.setAdapter(colorsAdapter); } // add Set Line Width Button builder.setPositiveButton(R.string.set_properties, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (colorStrokePropertiesChangeListener != null) { colorStrokePropertiesChangeListener.onPropertiesChanged(mCurrentColorStrokeObject); } } }); builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); return builder.create(); // return dialog }
From source file:at.flack.MailMainActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { prefs = getActivity().getSharedPreferences("mail", Context.MODE_PRIVATE); if (!prefs.getString("mailaddress", "").equals("")) { View rootView = inflater.inflate(R.layout.fragment_mail_main, container, false); loadmore = new LoadMoreAdapter(inflater.inflate(R.layout.contacts_loadmore, contactList, false)); contactList = (ListView) rootView.findViewById(R.id.listview); TextView padding = new TextView(getActivity()); padding.setHeight(10);/* ww w . ja va2s . co m*/ contactList.addHeaderView(padding); contactList.setHeaderDividersEnabled(false); contactList.addFooterView(loadmore.getView(), null, false); contactList.setFooterDividersEnabled(false); progressbar = rootView.findViewById(R.id.load_screen); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.attachToListView(contactList); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newMail = new Intent(getActivity(), NewMailActivity.class); getActivity().startActivity(newMail); } }); progressbar = rootView.findViewById(R.id.load_screen); if (MainActivity.getMailcontacts() == null) progressbar.setVisibility(View.VISIBLE); updateContactList(((MainActivity) this.getActivity())); swipe = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container); swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (getActivity() instanceof MainActivity) { MainActivity.mailprofile = null; ((MainActivity) getActivity()).emailLogin(1, 0, limit); } } }); contactList.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int topRowVerticalPosition = (contactList == null || contactList.getChildCount() == 0) ? 0 : contactList.getChildAt(0).getTop(); swipe.setEnabled(topRowVerticalPosition >= 0); } }); contactList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (MainActivity.getListItems() == null) { updateContactList((MainActivity) getActivity()); } openMessageActivity(getActivity(), arg2 - 1); } }); loadmore.getView().setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { loadmore.setEnabled(false); MainActivity.mailprofile = null; limit += 12; ((MainActivity) getActivity()).emailLogin(1, 0, limit); } }); setRetainInstance(true); return rootView; } else { View rootView = inflater.inflate(R.layout.fragment_email_login, container, false); final EditText mail = (EditText) rootView.findViewById(R.id.email); final EditText password = (EditText) rootView.findViewById(R.id.password); final EditText host = (EditText) rootView.findViewById(R.id.host); final EditText port = (EditText) rootView.findViewById(R.id.port); final EditText smtphost = (EditText) rootView.findViewById(R.id.smtphost); final EditText smtpport = (EditText) rootView.findViewById(R.id.smtpport); final Button login_button = (Button) rootView.findViewById(R.id.login_button); final RadioGroup radioGroup = (RadioGroup) rootView.findViewById(R.id.radioGroup); final RadioButton imap = (RadioButton) rootView.findViewById(R.id.radioButtonImap); radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { host.setVisibility(View.VISIBLE); port.setVisibility(View.VISIBLE); smtphost.setVisibility(View.VISIBLE); smtpport.setVisibility(View.VISIBLE); } }); login_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int at = mail.getText().toString().indexOf("@"); int dot = mail.getText().toString().lastIndexOf("."); if (mail.getText().length() <= 0 || at < 0 || dot < 0) { Toast.makeText(MailMainActivity.this.getActivity(), getResources().getString(R.string.facebook_login_please_enter_valid_mail), Toast.LENGTH_SHORT).show(); return; } if (password.getText().length() <= 0) { Toast.makeText(MailMainActivity.this.getActivity(), getResources().getString(R.string.facebook_login_please_enter_valid_pw), Toast.LENGTH_SHORT).show(); return; } String hostPart = mail.getText().toString().substring(at + 1, dot); MailAccounts mailacc = null; try { mailacc = MailAccounts.valueOf(hostPart.toUpperCase(Locale.GERMAN)); } catch (IllegalArgumentException e) { } if (mailacc == null) { radioGroup.setVisibility(View.VISIBLE); if (host.getText().toString().isEmpty() || port.getText().toString().isEmpty() || smtphost.getText().toString().isEmpty() || smtpport.getText().toString().isEmpty()) { Toast.makeText(MailMainActivity.this.getActivity(), MailMainActivity.this.getActivity().getResources().getString( R.string.activity_mail_enter_more_information), Toast.LENGTH_LONG).show(); return; } prefs.edit().putString("mailsmtp", smtphost.getText().toString()).apply(); prefs.edit().putInt("mailsmtpport", Integer.parseInt(smtpport.getText().toString())); prefs.edit().putString("mailimap", host.getText().toString()).apply(); prefs.edit().putInt("mailimapport", Integer.parseInt(port.getText().toString())).apply(); prefs.edit().putBoolean("mailuseimap", imap.isChecked()).apply(); } login_button.setEnabled(false); login_button.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY); prefs.edit().putString("mailaddress", mail.getText().toString()).apply(); prefs.edit().putString("mailpassword", password.getText().toString()).apply(); if (mailacc != null) { prefs.edit().putString("mailsmtp", mailacc.getSmtpHost()).apply(); prefs.edit().putInt("mailsmtpport", mailacc.getSMTPPort()); prefs.edit().putString("mailimap", mailacc.getHost()).apply(); prefs.edit().putInt("mailimapport", mailacc.getPort()).apply(); prefs.edit().putBoolean("mailuseimap", true).apply(); } prefs.edit().commit(); ((MainActivity) getActivity()).emailLogin(0); } }); setRetainInstance(true); return rootView; } }
From source file:net.konyan.yangonbusonthemap.HomeActivity.java
private void initUi(Bundle saveState) { ImageView ivMenu = (ImageView) findViewById(R.id.iv_action_menu); ivMenu.setOnClickListener(new View.OnClickListener() { @Override/* ww w. ja va 2s. c o m*/ public void onClick(View view) { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.openDrawer(GravityCompat.START); } }); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); initBottomSheet(); View view = navigationView.getHeaderView(0); RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.rg_language); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i) { case R.id.nav_radio_lan_en: language = LANGUAGE_EN; MyPref.putInt(KEY_LANGUAGE, LANGUAGE_EN); break; case R.id.nav_radio_lan_mm: language = LANGUAGE_MM; MyPref.putInt(KEY_LANGUAGE, LANGUAGE_MM); break; case R.id.nav_radio_lan_zg: language = LANGUAGE_ZG; MyPref.putInt(KEY_LANGUAGE, LANGUAGE_ZG); break; } initData(); if (nearByMarkers != null) { clearMarkers(nearByMarkers, null); } if (layerLine != null) { layerLine.removeLayerFromMap(); } if (busRouteMarkers != null) { clearMarkers(busRouteMarkers, null); currentSelectBus = -1; } mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); } }); switch (language) { case LANGUAGE_EN: ((RadioButton) view.findViewById(R.id.nav_radio_lan_en)).setChecked(true); break; case LANGUAGE_MM: ((RadioButton) view.findViewById(R.id.nav_radio_lan_mm)).setChecked(true); break; case LANGUAGE_ZG: ((RadioButton) view.findViewById(R.id.nav_radio_lan_zg)).setChecked(true); break; } if (saveState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.content_home, YangonMapFragment.newInstance(null, null)).commit(); } }
From source file:sliding_tab.SlidingTabs.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public View getView(final int position, View convertView, ViewGroup viewGroup) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.event_attending_list_item, null); TextView name = (TextView) convertView.findViewById(R.id.tv_ea_list_item); final RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { ArrayList<String>[] dbResult = Helper.getFriends_From_Event(Event_ID); switch (radioGroup.getCheckedRadioButtonId()) { case R.id.rb_ea_list_yes: { Update_Attending(dbResult, Constants.Yes, position); break; }/* w ww. ja v a 2 s .c om*/ case R.id.rb_ea_list_maybe: { Update_Attending(dbResult, Constants.Maybe, position); break; } case R.id.rb_ea_list_no: { Update_Attending(dbResult, Constants.No, position); break; } } } }); ArrayList<String>[] dbResult = Helper.getFriends_From_Event(Event_ID); //name.setText(dbResult[1].get(position)); name.setText(Helper.getNickname(dbResult[1].get(position))); switch (dbResult[2].get(position)) { case Constants.Yes: { radioGroup.check(R.id.rb_ea_list_yes); break; } case Constants.Maybe: { radioGroup.check(R.id.rb_ea_list_maybe); break; } case Constants.No: { radioGroup.check(R.id.rb_ea_list_no); break; } default: { break; } } if (!dbResult[1].get(position).equals(Constants.MY_User_ID)) { for (int i = 0; i < radioGroup.getChildCount(); i++) { radioGroup.getChildAt(i).setEnabled(false); } } return convertView; }
From source file:jmri.enginedriver.intro_theme.java
@SuppressWarnings("ConstantConditions") @Override//from w ww.j av a 2s . com public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.d("Engine_Driver", "intro_theme"); super.onActivityCreated(savedInstanceState); prefs = this.getActivity().getSharedPreferences("jmri.enginedriver_preferences", 0); currentValue = prefs.getString("prefTheme", this.getActivity().getApplicationContext().getResources() .getString(R.string.prefThemeDefaultValue)); nameEntries = this.getActivity().getApplicationContext().getResources() .getStringArray(R.array.prefThemeEntries); nameEntryValues = this.getActivity().getApplicationContext().getResources() .getStringArray(R.array.prefThemeEntryValues); v = (RadioButton) getView().findViewById(R.id.intro_theme_default_name); v.setText(nameEntries[0]); v = (RadioButton) getView().findViewById(R.id.intro_theme_black_name); v.setText(nameEntries[1]); v = (RadioButton) getView().findViewById(R.id.intro_theme_outline_name); v.setText(nameEntries[2]); v = (RadioButton) getView().findViewById(R.id.intro_theme_ultra_name); v.setText(nameEntries[3]); v = (RadioButton) getView().findViewById(R.id.intro_theme_colorful_name); v.setText(nameEntries[4]); RadioGroup radioGroup = getView().findViewById(R.id.intro_throttle_type_radio_group); radioGroup.clearCheck(); if (nameEntryValues[0].equals(currentValue)) { radioGroup.check(R.id.intro_theme_default_name); } else if (nameEntryValues[1].equals(currentValue)) { radioGroup.check(R.id.intro_theme_black_name); } else if (nameEntryValues[2].equals(currentValue)) { radioGroup.check(R.id.intro_theme_outline_name); } else if (nameEntryValues[3].equals(currentValue)) { radioGroup.check(R.id.intro_theme_ultra_name); } else if (nameEntryValues[4].equals(currentValue)) { radioGroup.check(R.id.intro_theme_colorful_name); } radioGroup.jumpDrawablesToCurrentState(); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @SuppressLint("ApplySharedPref") @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int Choice = 0; if (checkedId == R.id.intro_theme_default_name) { Choice = 0; } else if (checkedId == R.id.intro_theme_black_name) { Choice = 1; } else if (checkedId == R.id.intro_theme_outline_name) { Choice = 2; } else if (checkedId == R.id.intro_theme_ultra_name) { Choice = 3; } else if (checkedId == R.id.intro_theme_colorful_name) { Choice = 4; } prefs.edit().putString("prefTheme", nameEntryValues[Choice]).commit(); } }); }
From source file:com.cairoconfessions.MainActivity.java
public void report(View view) { final EditText edit = new EditText(this); final RadioGroup choices = new RadioGroup(this); edit.setText("I would like to report this confession"); final String[] selectedItem = getResources().getStringArray(R.array.report_choices); for (int i = 0; i < selectedItem.length; i++) { RadioButton choice = new RadioButton(this); choice.setText(selectedItem[i]); choices.addView(choice);/*from w w w .ja v a 2 s . c om*/ } choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected edit.setText("I would like to report this confession as " + ((RadioButton) group.findViewById(checkedId)).getText().toString()); } }); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(choices); ll.addView(edit); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Choose which categories:").setView(ll) .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button reportReceived(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked Cancel button } }).show(); }
From source file:jp.co.rediscovery.firstflight.ConfigFragment.java
/** * ??? FIXME //from w w w. j ava 2 s . c o m * @param root */ private void initConfigNetwork(final View root) { final IWiFiController wifi = (mController instanceof IWiFiController) ? (IWiFiController) mController : null; final RadioGroup group = root.findViewById(R.id.network_wifi_mode_radiogroup); if (wifi != null) { final boolean outdoor = wifi.isOutdoor(); group.check(outdoor ? R.id.network_outdoor_radiobutton : R.id.network_indoor_radiobutton); group.setOnCheckedChangeListener(mOnRadioButtonCheckedChangeListener); } else { group.check(R.id.network_indoor_radiobutton); group.setEnabled(false); } }
From source file:com.google.code.twisty.Twisty.java
/** Have our activity manage and persist dialogs, showing and hiding them */ @Override/*from w w w . j a v a2 s .c om*/ protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ENTER_WRITEFILE: LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate(R.layout.save_file_prompt, null); final EditText et = (EditText) textEntryView.findViewById(R.id.savefile_entry); return new AlertDialog.Builder(Twisty.this).setTitle("Write to file").setView(textEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { savefile_path = savegame_dir + "/" + et.getText().toString(); // Directly modify the message-object passed to us by the terp thread: dialog_message.path = savefile_path; // Wake up the terp thread again synchronized (glkLayout) { glkLayout.notify(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // This makes op_save() fail. dialog_message.path = ""; // Wake up the terp thread again synchronized (glkLayout) { glkLayout.notify(); } } }).create(); case DIALOG_ENTER_READFILE: restoredialog = new Dialog(Twisty.this); restoredialog.setContentView(R.layout.restore_file_prompt); restoredialog.setTitle("Read a file"); android.widget.RadioGroup rg = (RadioGroup) restoredialog.findViewById(R.id.radiomenu); updateRestoreRadioButtons(rg); android.widget.Button okbutton = (Button) restoredialog.findViewById(R.id.restoreokbutton); okbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { android.widget.RadioGroup rg = (RadioGroup) restoredialog.findViewById(R.id.radiomenu); int checkedid = rg.getCheckedRadioButtonId(); if (rg.getChildCount() == 0) { // no saved games: FAIL savefile_path = ""; } else if (checkedid == -1) { // no game selected RadioButton firstbutton = (RadioButton) rg.getChildAt(0); // default to first game savefile_path = savegame_dir + "/" + firstbutton.getText(); } else { RadioButton checkedbutton = (RadioButton) rg.findViewById(checkedid); savefile_path = savegame_dir + "/" + checkedbutton.getText(); } dismissDialog(DIALOG_ENTER_READFILE); // Return control to the z-machine thread dialog_message.path = savefile_path; synchronized (glkLayout) { glkLayout.notify(); } } }); android.widget.Button cancelbutton = (Button) restoredialog.findViewById(R.id.restorecancelbutton); cancelbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dismissDialog(DIALOG_ENTER_READFILE); // Return control to the z-machine thread dialog_message.path = ""; synchronized (glkLayout) { glkLayout.notify(); } } }); return restoredialog; case DIALOG_CHOOSE_GAME: choosegamedialog = new Dialog(Twisty.this); choosegamedialog.setContentView(R.layout.choose_game_prompt); choosegamedialog.setTitle("Choose Game"); android.widget.RadioGroup zrg = (RadioGroup) choosegamedialog.findViewById(R.id.game_radiomenu); updateGameRadioButtons(zrg); zrg.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { dismissDialog(DIALOG_CHOOSE_GAME); String path = (String) game_paths.get(checkedId); if (path != null) { stopTerp(); startTerp(path); } } }); return choosegamedialog; case DIALOG_CANT_SAVE: return new AlertDialog.Builder(Twisty.this).setTitle("Cannot Access Games") .setMessage("Twisty Games folder is not available on external media.") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // A path of "" makes op_save() fail. dialog_message.path = ""; // Wake up the terp thread again synchronized (glkLayout) { glkLayout.notify(); } } }).create(); case DIALOG_NO_SDCARD: return new AlertDialog.Builder(Twisty.this).setTitle("No External Media") .setMessage("Cannot find sdcard or other media.") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).create(); } return null; }
From source file:jmri.enginedriver.intro_throttle_type.java
@SuppressWarnings("ConstantConditions") @Override// www.ja v a 2s . co m public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.d("Engine_Driver", "intro_throttle_type"); super.onActivityCreated(savedInstanceState); prefs = this.getActivity().getSharedPreferences("jmri.enginedriver_preferences", 0); currentValue = prefs.getString("prefThrottleScreenType", this.getActivity().getApplicationContext() .getResources().getString(R.string.prefThrottleScreenTypeDefault)); nameEntries = this.getActivity().getApplicationContext().getResources() .getStringArray(R.array.prefThrottleScreenTypeEntries); nameEntryValues = this.getActivity().getApplicationContext().getResources() .getStringArray(R.array.prefThrottleScreenTypeEntryValues); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_default_name); v.setText(nameEntries[0]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_simple_name); v.setText(nameEntries[1]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_name); v.setText(nameEntries[2]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_big_left_name); v.setText(nameEntries[3]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_big_right_name); v.setText(nameEntries[4]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_left_name); v.setText(nameEntries[5]); v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_right_name); v.setText(nameEntries[6]); RadioGroup radioGroup = getView().findViewById(R.id.intro_throttle_type_radio_group); radioGroup.clearCheck(); if (nameEntryValues[0].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_default_name); } else if (nameEntryValues[1].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_simple_name); } else if (nameEntryValues[2].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_vertical_name); } else if (nameEntryValues[3].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_big_left_name); } else if (nameEntryValues[4].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_big_right_name); } else if (nameEntryValues[5].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_vertical_left_name); } else if (nameEntryValues[6].equals(currentValue)) { radioGroup.check(R.id.intro_throttle_type_vertical_right_name); } radioGroup.jumpDrawablesToCurrentState(); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @SuppressLint("ApplySharedPref") @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int Choice = 0; if (checkedId == R.id.intro_throttle_type_default_name) { Choice = 0; } else if (checkedId == R.id.intro_throttle_type_simple_name) { Choice = 1; } else if (checkedId == R.id.intro_throttle_type_vertical_name) { Choice = 2; } else if (checkedId == R.id.intro_throttle_type_big_left_name) { Choice = 3; } else if (checkedId == R.id.intro_throttle_type_big_right_name) { Choice = 4; } else if (checkedId == R.id.intro_throttle_type_vertical_left_name) { Choice = 5; } else if (checkedId == R.id.intro_throttle_type_vertical_right_name) { Choice = 6; } prefs.edit().putString("prefThrottleScreenType", nameEntryValues[Choice]).commit(); } }); }