This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new AlertDialog.Builder(this) | |
| .setIcon(android.R.drawable.ic_dialog_alert) | |
| .setTitle("Are you sure?") | |
| .setMessage("Do you really want to do this?") | |
| .setPositiveButton("Yes", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialog, int which) { | |
| Toast.makeText(MainActivity.this, "It's Done", Toast.LENGTH_SHORT).show(); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MainActivity.notesArrayList.set(position,txtNote.getText().toString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| txtNote.addTextChangedListener(new TextWatcher() { | |
| @Override | |
| public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| } | |
| @Override | |
| public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| MainActivity.notesArrayList.set(position, String.valueOf(s)); | |
| MainActivity.populateNotesArrayListLimited(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SQLLite : Server Query Language | |
| // We are going to Create a database and table inside that and save some data in table and pull data out of the table. | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| try { | |
| // Stage 1: Creating our database | |
| SQLiteDatabase myDatabase = this.openOrCreateDatabase("Users", MODE_PRIVATE, null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // To display web content within an app, we use WebView. it allow us display html content. | |
| // First ask for internet permission in the android manifest. | |
| WebView webView=findViewById(R.id.webView); | |
| webView.getSettings().setJavaScriptEnabled(true); | |
| // The following line is because if we don't use this line, in some cases the phone will | |
| // jump to default browser on the phone. | |
| webView.setWebViewClient(new WebViewClient()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String sql = "INSERT INTO articles (articleId, title, content) VALUES (? , ? , ?)"; | |
| SQLiteStatement statement = articlesDB.compileStatement(sql); | |
| statement.bindString(1, articleId); | |
| statement.bindString(2, articleTitle); | |
| statement.bindString(3, articleContent); | |
| statement.execute(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Saving Data Using ParseObject | |
| ParseObject score = new ParseObject("Score"); | |
| score.put("username", "Mohammad"); //This line saves a username object in the class Score with the value of Mohammad | |
| score.put("score", 85); //Adding score to the Score. This will be an Integer. | |
| score.saveInBackground(new SaveCallback() { | |
| @Override | |
| public void done(ParseException e) { | |
| // Called when the save is done eather successfully or not. the easiest way to check to see if | |
| // it has been successful is to look for an error or exception. | |
| if (e == null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Advance Query On a class with criteria | |
| ParseQuery<ParseObject> query = ParseQuery.getQuery("Score"); | |
| query.whereEqualTo("username", "Mohammad"); | |
| query.setLimit(1); | |
| query.findInBackground(new FindCallback<ParseObject>() { | |
| @Override | |
| public void done(List<ParseObject> objects, ParseException e) { | |
| if (e == null) { | |
| Log.i("Lord-FindInBack", "Retrieved" + objects.size()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Parse Server Users | |
| // This allow us to signup and login users , and those users remain logged in as long as using the app. | |
| //Signing Up Users: | |
| ParseUser user=new ParseUser(); | |
| user.setUsername("lord"); | |
| user.setPassword("pass"); | |
| user.signUpInBackground(new SignUpCallback() { | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Hiding the Keyboard | |
| InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService((this.INPUT_METHOD_SERVICE)); | |
| inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); | |
| Link to Visit: https://stackoverflow.com/questions/4165414/how-to-hide-soft-keyboard-on-android-after-clicking-outside-edittext |