@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.eighttry, container, false); getActivity().setTitle(NavigationActivity.header); okBtn = (Button) rootView.findViewById(R.id.button1); clearBtn = (Button) rootView.findViewById(R.id.button2); editText1 = (EditText) rootView.findViewById(R.id.editText1); listener1 = editText1.getKeyListener(); editText1.setText(""); step2 = (TextView) rootView.findViewById(R.id.textView2); step1 = (TextView) rootView.findViewById(R.id.textView3); tryone = (View) rootView.findViewById(R.id.tryone); trytwo = (View) rootView.findViewById(R.id.trytwo); tryonetxt2 = (EditText) tryone.findViewById(R.id.txt2); tryonetxt4 = (EditText) tryone.findViewById(R.id.txt4); tryonebtn1 = (Button) tryone.findViewById(R.id.btn1); tryonebtn2 = (Button) tryone.findViewById(R.id.btn2); trytwotxt2 = (EditText) trytwo.findViewById(R.id.txt2); trytwobtn1 = (Button) trytwo.findViewById(R.id.btn1); clearBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub editText1.setText(""); editText1.setKeyListener(listener1); hideSoftKeyboard(); tryone.setVisibility(View.GONE); trytwo.setVisibility(View.GONE); tryonetxt2.setText(""); tryonetxt4.setText(""); } }); okBtn.setOnClickListener( new View.OnClickListener() { private Animation RightSwipe1; @Override public void onClick(View v) { // TODO Auto-generated method stub if (editText1.getText().toString().equalsIgnoreCase("")) { hideSoftKeyboard(); step2.setClickable(false); step1.setClickable(false); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter numbers") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else if (!editText1.getText().toString().equalsIgnoreCase("")) { editText1.setKeyListener(null); x = Integer.valueOf(editText1.getText().toString()); step1.setClickable(true); RightSwipe1 = AnimationUtils.loadAnimation(getActivity(), R.anim.leftside); tryone.startAnimation(RightSwipe1); tryone.setVisibility(View.VISIBLE); trytwo.setVisibility(View.GONE); tryonetxt2.setText(""); tryonetxt2.requestFocus(); tryonetxt2.setCursorVisible(true); getActivity().overridePendingTransition(R.anim.slideleft1, R.anim.slideleft2); hideSoftKeyboard(); } } }); btnsolutionone = (Button) rootView.findViewById(R.id.btnsolutionone); btnsolutionone.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.eightthsolutionone); dialog.setTitle("Solution"); final TextView txt2 = (TextView) dialog.findViewById(R.id.txt2); final TextView txt4 = (TextView) dialog.findViewById(R.id.txt4); final TextView txt7 = (TextView) dialog.findViewById(R.id.txt7); txt2.setText( String.valueOf(99) + "+" + String.valueOf(1) + "=" + String.valueOf(99 + 1)); txt4.setText("i.e. " + String.valueOf(x)); txt7.setText(String.valueOf(x * 100)); dialog.show(); } }); btnsolutiontwo = (Button) rootView.findViewById(R.id.btnsolutiontwo); btnsolutiontwo.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.eightthsolutiontwo); dialog.setTitle("Solution"); final TextView txt2 = (TextView) dialog.findViewById(R.id.txt2); final TextView txt3 = (TextView) dialog.findViewById(R.id.txt3); final TextView txt5 = (TextView) dialog.findViewById(R.id.txt5); txt2.setText(String.valueOf("So " + String.valueOf(x * 100))); txt3.setText(String.valueOf(" -" + String.valueOf(x))); int s = x * 100; int a = s - x; txt5.setText(String.valueOf((x * 100) - x)); dialog.show(); } }); SpannableString content = new SpannableString(step1.getText().toString()); content.setSpan(new UnderlineSpan(), 0, step1.getText().toString().length(), 0); step1.setText(content); tryonebtn1.setOnClickListener( new View.OnClickListener() { private Animation RightSwipe1; @Override public void onClick(View v) { // TODO Auto-generated method stubs int quot = x / 10; int rem = x % 10; hideSoftKeyboard(); hideSoftKeyboard(); if (!tryonetxt2.getText().toString().equalsIgnoreCase("")) { if (Integer.valueOf(tryonetxt2.getText().toString()) == 99 + 1) { tryonetxt4.setText(""); tryonetxt4.requestFocus(); tryonetxt4.setCursorVisible(true); getActivity().overridePendingTransition(R.anim.slideleft1, R.anim.slideleft2); hideSoftKeyboard(); } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter correct answer") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter number") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } }); tryonebtn2.setOnClickListener( new View.OnClickListener() { private Animation RightSwipe1; @Override public void onClick(View v) { // TODO Auto-generated method stubs int quot = x / 10; int rem = x % 10; hideSoftKeyboard(); hideSoftKeyboard(); if (!tryonetxt4.getText().toString().equalsIgnoreCase("")) { if (Integer.valueOf(tryonetxt4.getText().toString()) == x * 100) { RightSwipe1 = AnimationUtils.loadAnimation(getActivity(), R.anim.leftside); trytwo.startAnimation(RightSwipe1); trytwo.setVisibility(View.VISIBLE); tryone.setVisibility(View.GONE); getActivity().overridePendingTransition(R.anim.slideleft1, R.anim.slideleft2); hideSoftKeyboard(); } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter correct answer") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter number") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } }); SpannableString content2 = new SpannableString(step2.getText().toString()); content2.setSpan(new UnderlineSpan(), 0, step2.getText().toString().length(), 0); step2.setText(content2); trytwobtn1.setOnClickListener( new View.OnClickListener() { private Animation RightSwipe2; @Override public void onClick(View v) { // TODO Auto-generated method stub hideSoftKeyboard(); if (!trytwotxt2.getText().toString().equalsIgnoreCase("")) { int quot = x / 10; int rem = x % 10; int m = quot + rem; /*if(String.valueOf(m).length()>1) { layout2number1.setText("Here we have "+m/10+" carry"); layout2number2.setText(" i.e. "+quot+" +|"+m/10+" |"+m%10+" "+rem); layout2number3.setText("So, the final answer is "+(quot+m/10)+""+m%10+""+rem); } else { layout2number1.setText(" i.e. "+"| "+quot+" |"+m+" "+rem); layout2number2.setText("So, the final answer is "+quot+""+m+""+rem); layout2number3.setVisibility(View.GONE); }*/ int s = x * 100; int a = s - x; if (trytwotxt2.getText().toString().equalsIgnoreCase(String.valueOf(a))) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Correct Answer") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter correct answer") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Message"); // set dialog message alertDialogBuilder .setMessage("Please enter number") .setCancelable(false) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } }); return rootView; }
private void initializeFields() { // Reference the buttons of Income Fragment. Button saveButton = (Button) getView().findViewById(R.id.save2); Button discardButton = (Button) getView().findViewById(R.id.discard2); // Reference the textViews of the Income Fragment. TextView dateTXT = (TextView) getView().findViewById(R.id.DateTxt); final TextView accountTXT = (TextView) getView().findViewById(R.id.AccountTxt); final TextView amountTXT = (TextView) getView().findViewById(R.id.AmountTxt); final TextView categoryTXT = (TextView) getView().findViewById(R.id.CategoryTxt); // Reference the editTexts of the Income Fragment. dateText = (EditText) getView().findViewById(R.id.Date); accountText = (EditText) getView().findViewById(R.id.Account); amountText = (EditText) getView().findViewById(R.id.Amount); categoryText = (EditText) getView().findViewById(R.id.Category); // Keyboard View keyListener = amountText.getKeyListener(); amountText.setKeyListener(null); // Constructor for the class that handles the database. myDBHandler = new dbHandler(getActivity(), null, null, 1); /** Setting all editTexts not Editable */ dateText.setKeyListener(null); accountText.setKeyListener(null); amountText.setKeyListener(null); categoryText.setKeyListener(null); /** * Setting the click listeners used by the textViews. Setting the popup windows that will appear * upon click. */ // Setting the click listener for the Date textView. dateDefault(); dateTXT.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog( getActivity(), date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)) .show(); } }); accountTXT.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { accountDialog(); } }); // ########################################################################################## // ########################################################################################## amountTXT.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialogBuilder = new AlertDialog.Builder(getActivity()); dialogBuilder.setTitle(R.string.amountTitle); dialogBuilder.setMessage(R.string.amountPrompt); dialogBuilder.setCancelable(false); final EditText money_entered = new EditText(getView().getContext()); money_entered.setInputType(InputType.TYPE_CLASS_PHONE); dialogBuilder.setView(money_entered); dialogBuilder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String salarySTR = money_entered.getEditableText().toString(); if (salarySTR.contains(",")) { salarySTR = salarySTR.replace(',', '.'); } if (amountValidation(salarySTR) == 1) { amountEntered = Double.parseDouble(salarySTR); amountEntered = twoDecimals.roundTwoDecimals(amountEntered); amountText.setText(salarySTR); } } }); dialogBuilder.setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = dialogBuilder.create(); alert.show(); } }); // ########################################################################################## // ########################################################################################## categoryTXT.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { categoryDialog(); } }); /** Setting the click listeners used by the buttons of the view. */ saveButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dateStr = dateText.getText().toString(); accountStr = accountText.getText().toString(); amountStr = amountText.getText().toString(); categoryStr = categoryText.getText().toString(); // Popup message in case where some of the fields are not filled. if (dateStr.equals("") || amountStr.equals("") || accountStr.equals("") || categoryStr.equals("")) { Toast.makeText(getActivity(), R.string.fields_required, Toast.LENGTH_SHORT).show(); } // If all textFields are filled proceed(BUG FIXED). else { if (amountStr.contains(",")) { amountStr.replace(',', '.'); } resultValidation = amountValidation(amountStr); /** 2 decimal digits for all doubles. */ if (resultValidation == 1) { amountEntered = Double.parseDouble(amountStr); amountEntered = twoDecimals.roundTwoDecimals(amountEntered); Transactions transaction = new Transactions( dateStr, categoryStr, accountStr, amountEntered, incomeFrag, 0.0); myDBHandler.addRow(transaction); Toast.makeText(getActivity(), R.string.saved_all, Toast.LENGTH_SHORT).show(); } else { amountText.setText(""); } } } }); // Setting the action performed by the DISCARD button on main screen. discardButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { clearData(); } }); }