List of usage examples for android.app Dialog setContentView
public void setContentView(@NonNull View view)
From source file:com.orange.datavenue.StreamListFragment.java
/** * *///from w w w . j av a 2 s .com private void deleteStream() { final android.app.Dialog dialog = new android.app.Dialog(getActivity()); dialog.setContentView(R.layout.delete_dialog); dialog.setTitle(R.string.delete); TextView info = (TextView) dialog.findViewById(R.id.info_label); info.setText(String.format(getString(R.string.delete_stream), Model.instance.currentStream.getId())); Button deleteButton = (Button) dialog.findViewById(R.id.delete_button); deleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId()); Log.d(TAG_NAME, "stream : " + Model.instance.currentStream.getId()); DeleteStreamOperation deleteStreamOperation = new DeleteStreamOperation(Model.instance.oapiKey, Model.instance.key, Model.instance.currentDatasource, Model.instance.currentStream, new OperationCallback() { @Override public void process(Object object, Exception exception) { if (exception == null) { getStreams(); // reload } else { Errors.displayError(getActivity(), exception); } } }); deleteStreamOperation.execute(""); dialog.dismiss(); } }); Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button); cancelDeleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.setCancelable(false); dialog.show(); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to add an app to a row. The user can add the * app to an existing row or a new row.//from w ww . j a v a 2s . c om * * @param context * @param applications */ public static void displayAddApps(final Launcher context, final ArrayList<ApplicationInfo> applications) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_apps_grid); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, true))); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position); boolean currentRow = !newRadioButton.isChecked(); context.addItem(itemInfo, currentRow ? null : name); context.showCover(false); dialog.dismiss(); if (currentRow) { Analytics.logEvent(Analytics.DIALOG_ADD_APP); } else { Analytics.logEvent(Analytics.ADD_APP_WITH_ROW); } } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_APP); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the Spotlight web apps: * https://www.google.com/tv/spotlight-gallery.html Allow the user to add a * web app to an existing row or a new row. * /*from w w w . j ava2s. c o m*/ * @param context */ public static void displayAddSpotlight(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_apps_grid); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context); gridView.setAdapter(new AllSpotlightAdapter(context, spotlights)); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position); boolean currentRow = !newRadioButton.isChecked(); context.addItem(itemInfo, currentRow ? null : name); context.showCover(false); dialog.dismiss(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP); } else { Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP_WITH_ROW); } } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SPOTLIGHT_WEB_APP); }
From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java
private void setRecyclerViewAdapter() { sharesList = databaseHandler.getShares(); purchaseList = databaseHandler.getPurchases(); if (sharesList.size() < 1) { emptyTV.setVisibility(View.VISIBLE); arrow.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (getResources().getConfiguration().orientation == 1) { arrow.setBackground(getResources().getDrawable(R.drawable.curved_line_vertical)); } else { arrow.setBackground((getResources().getDrawable(R.drawable.curved_line_horizontal))); }/* ww w. j a va2s .co m*/ } } else { emptyTV.setVisibility(View.GONE); arrow.setVisibility(View.GONE); } PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), purchaseList); purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, int position) { final Purchase purchase = purchaseList.get(position); final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Edit Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); newRB.setVisibility(View.GONE); existingRB.setChecked(true); name.setVisibility(View.GONE); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); int pos = 0; for (int i = 0; i < sharesList.size(); i++) { shares.add(sharesList.get(i).getName()); if (sharesList.get(i).getName().equals(purchase.getName())) pos = i; } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); spinner.setSelection(pos); spinner.setVisibility(View.VISIBLE); final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); final EditText price = (EditText) dialog.findViewById(R.id.buying_price); quantity.setText(String.valueOf(purchase.getQuantity())); price.setText(String.valueOf(purchase.getPrice())); Calendar calendar = Calendar.getInstance(); calendar.setTime(purchase.getDate()); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(PurchaseShareFragment.this); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase p = new Purchase(); p.setId(purchase.getId()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); p.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } try { p.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } try { p.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } p.setType("buy"); p.setName(spinner.getSelectedItem().toString()); databaseHandler.updatePurchase(p); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); sharePurchasesRecyclerView.setHasFixedSize(true); sharePurchasesRecyclerView.setAdapter(purchaseAdapter); sharePurchasesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); }
From source file:com.cjc.activity.carManagement.CarDisassemblyTypeActivity.java
private void createDialog(final int way) { // 2: 3: 4:/* www .ja va 2s .com*/ String message = ""; if (way == 1) { message = ""; } else if (way == 2) { message = ""; } else if (way == 3) { message = ""; } else if (way == 4) { message = ""; } final Dialog dialog = new Dialog(context, R.style.DialogNoTitle); View view = View.inflate(context, R.layout.dlg_dismantling, null); dialog.setContentView(view); TextView mTvUpdateMsg = (TextView) view.findViewById(R.id.tvTypeContent); mTvUpdateMsg.setText(message); Button btnOk = (Button) view.findViewById(R.id.btnOk); Button btnCancel = (Button) view.findViewById(R.id.btnCancel); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadCheckTypeData(way); dialog.dismiss(); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display about dialog to user when invoked from menu option. * /*from w w w . j a v a2 s.c om*/ * @param context */ public static void displayAbout(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about); Typeface lightTypeface = ((LauncherApplication) context.getApplicationContext()).getLightTypeface(context); TextView aboutTextView = (TextView) dialog.findViewById(R.id.about_text1); aboutTextView.setTypeface(lightTypeface); aboutTextView.setText(context.getString(R.string.about_version_title, Utils.getVersion(context))); aboutTextView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { context.showCover(false); dialog.dismiss(); Intent intent = new Intent(context, EasterEggActivity.class); context.startActivity(intent); Analytics.logEvent(Analytics.EASTER_EGG); return true; } }); TextView copyrightTextView = (TextView) dialog.findViewById(R.id.copyright_text); copyrightTextView.setTypeface(lightTypeface); TextView feedbackTextView = (TextView) dialog.findViewById(R.id.feedback_text); feedbackTextView.setTypeface(lightTypeface); ((Button) dialog.findViewById(R.id.button_web)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_web_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_WEB_SITE); context.showCover(false); dialog.dismiss(); } }); ((Button) dialog.findViewById(R.id.button_privacy_policy)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_privacy_policy_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_PRIVACY_POLICY); context.showCover(false); dialog.dismiss(); } }); ((Button) dialog.findViewById(R.id.button_more_apps)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_more_apps_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_MORE_APPS); context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ABOUT); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Prompt the user to rate the app./*w ww .jav a 2s . co m*/ * * @param context */ public static void displayRating(final Launcher context) { SharedPreferences prefs = context.getSharedPreferences(Launcher.PREFERENCES_NAME, Activity.MODE_PRIVATE); if (prefs.getBoolean(DONT_SHOW_RATING_AGAIN, false)) { return; } final SharedPreferences.Editor editor = prefs.edit(); // Get date of first launch Long date_firstLaunch = prefs.getLong(DATE_FIRST_LAUNCHED, 0); if (date_firstLaunch == 0) { date_firstLaunch = System.currentTimeMillis(); editor.putLong(DATE_FIRST_LAUNCHED, date_firstLaunch); } // Wait at least n days before opening if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.confirmation); TextView confirmationTextView = (TextView) dialog.findViewById(R.id.confirmationText); confirmationTextView.setText(context.getString(R.string.rating_message)); Button buttonYes = (Button) dialog.findViewById(R.id.button1); buttonYes.setText(context.getString(R.string.dialog_yes)); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.entertailion.android.launcher")); context.startActivity(intent); if (editor != null) { editor.putBoolean(DONT_SHOW_RATING_AGAIN, true); editor.commit(); } Analytics.logEvent(Analytics.RATING_YES); context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.button2); buttonNo.setText(context.getString(R.string.dialog_no)); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (editor != null) { editor.putBoolean(DONT_SHOW_RATING_AGAIN, true); editor.commit(); } Analytics.logEvent(Analytics.RATING_NO); context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); } editor.commit(); }
From source file:com.zapto.park.ParkActivity.java
public boolean onOptionsItemSelected(MenuItem item) { Intent i = null;/*w w w. ja v a2 s . c om*/ switch (item.getItemId()) { // Add User case 1: Dialog d = new Dialog(cActivity); final Dialog dialog = d; d.setContentView(R.layout.dialog_add_employee); d.setTitle(R.string.create_user_title); final EditText first_name = (EditText) d.findViewById(R.id.employee_first); final EditText last_name = (EditText) d.findViewById(R.id.employee_last); Button button_getinfo = (Button) d.findViewById(R.id.button_getinfo); button_getinfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EmployeeDB edb = new EmployeeDB(context); String first = first_name.getText().toString(); String last = last_name.getText().toString(); ContentValues cv = new ContentValues(); cv.put("totable_first", first); cv.put("totable_last", last); cv.put("totable_license", Globals.LICENSE_KEY); // Log request in database. ContentValues cv2 = new ContentValues(); cv2.put("first", first); cv2.put("last", last); // Query database. edb.insertEmployee(cv2); // Close our database. edb.close(); dialog.dismiss(); } }); d.show(); break; // Settings case 2: Log.i(LOG_TAG, "Settings menu clicked."); i = new Intent(this, SettingsActivity.class); startActivity(i); break; case 3: Log.i(LOG_TAG, "View Log Loading."); i = new Intent(this, ListViewActivity.class); startActivity(i); break; case 4: doInit(); Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { updateEmployees(); doPendingRequests(); } }); break; case 5: Log.i(LOG_TAG, "SendEmailActivity Loading."); i = new Intent(this, SendEmailActivity.class); startActivity(i); break; case 6: Log.i(LOG_TAG, "View Log Loading."); i = new Intent(this, ListViewActivity.class); startActivity(i); break; } return true; }
From source file:com.bitants.wally.fragments.ImageZoomFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (getActivity() != null) { final Dialog dialog = new Dialog(getActivity()); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.activity_image_zoom); dialog.getWindow().setBackgroundDrawableResource(R.color.Transparent); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.copyFrom(dialog.getWindow().getAttributes()); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.getWindow().setAttributes(layoutParams); initToolbar(dialog);/*from ww w . j av a 2s . c o m*/ progressBar = dialog.findViewById(R.id.zoom_loader); zoomableImageView = (PhotoView) dialog.findViewById(R.id.image_zoom_photoview); if (bitmap != null) { if (rect != null) { animateIn(dialog); } } else if (fileUri != null) { showLoader(); Glide.with(getActivity()).load(fileUri).fitCenter() .listener(new RequestListener<Uri, GlideDrawable>() { @Override public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { hideLoader(); return false; } }).into(zoomableImageView); } else { dismiss(); } photoViewAttacher = new PhotoViewAttacher(zoomableImageView); photoViewAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { @Override public void onViewTap(View view, float x, float y) { dismiss(); } }); return dialog; } else { return null; } }
From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java
@Nullable @Override//from w w w. j a v a 2s . c o m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false); databaseHandler = new DatabaseHandler(getContext()); sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view); emptyTV = (TextView) root.findViewById(R.id.empty); arrow = (ImageView) root.findViewById(R.id.arrow); setRecyclerViewAdapter(); FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab); addPurchaseFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); List<String> nseList = ShareUtils.getNseList(getContext()); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, nseList); name.setAdapter(arrayAdapter); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); if (shares.size() == 0) existingRB.setVisibility(View.GONE); (newRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } }); (existingRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(this); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Share share = new Share(); share.setId(databaseHandler.getNextKey("share")); share.setPurchases(new RealmList<Purchase>()); Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); if (newRB.isChecked()) { String sName = name.getText().toString().trim(); if (sName.equals("")) { Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show(); return; } else { share.setName(sName); purchase.setName(sName); } } String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); share.setDateOfInitialPurchase(date); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.buying_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("buy"); if (newRB.isChecked()) { if (!databaseHandler.addShare(share, purchase)) { Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show(); return; } } else { purchase.setName(spinner.getSelectedItem().toString()); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); } setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }