Skip to content

Instantly share code, notes, and snippets.

View MohammadSamandari's full-sized avatar
💭
Android Is SO MUCH FUN

Mohammad Samandari MohammadSamandari

💭
Android Is SO MUCH FUN
View GitHub Profile
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();
}
})
MainActivity.notesArrayList.set(position,txtNote.getText().toString());
@MohammadSamandari
MohammadSamandari / Android-EditTExt-addTextChangeListener.java
Created April 5, 2019 12:03
Listener for text change in the edit text
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();
@MohammadSamandari
MohammadSamandari / Android-SQLite.java
Last active April 5, 2019 13:47
Working with SQLite , create database, table, insert,get
// 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);
// 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());
@MohammadSamandari
MohammadSamandari / SQLiteStatement.java
Created April 17, 2019 21:32
Insert Data into database using sqlite statement
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();
@MohammadSamandari
MohammadSamandari / Android-ParseServer.java
Created April 28, 2019 20:52
ParseObject Add, Query, Update
//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) {
@MohammadSamandari
MohammadSamandari / Android-ParseServer.java
Created April 29, 2019 16:46
Advance Query In Parse Server
//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());
@MohammadSamandari
MohammadSamandari / Android-ParseServer.java
Created April 29, 2019 19:46
Working with Parse Server User. SignUp, Login, Check Login , Log Out
// 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
@MohammadSamandari
MohammadSamandari / Android-HideKeyboard.java
Last active April 30, 2019 16:25
hiding keyboard when clicking on a view
//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