Monday , January 10 2022

Android Room Database Example – Building a Todo App – Android Coding by DMTechnolab

The package The trap.Simplified coding.Maytodo;

Import Android.Content.Dialog interface;

Import Android.Content.Intent;

Import Android..AsyncTask;

Import Android.Support.v7.App.AlertDialog;

Import Android.Support.v7.App.AppCompatActivity;

Import Android..Bundle;

Import Android.Opinion.Opinion;

Import Android.Widget.Checkbox;

Import Android.Widget.Change in writing;

Import Android.Widget.Toast;

public class UpdateTaskActivity Is spread AppCompatActivity {{

Private Change in writing editTextTask, EditTextDesc, editTextFinishBy;

Private Checkbox checkBoxFinished;

@ Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.activity_update_task);

editTextTask = = findViewById()R.Id.editTextTask);

editTextDesc = = findViewById()R.Id.EditTextDesc);

editTextFinishBy = = findViewById()R.Id.editTextFinishBy);

checkBoxFinished = = findViewById()R.Id.checkBoxFinished);

The last Work Work = = ()Work) Get()).getSerializableExtra()“Work”);

burden()Work);

findViewById()R.Id.Button_update).setOnClickListener()New Opinion.OnClickListener()) {{

@ Override

public Zero on click()Opinion Opinion) {{

Toast.Makeup()getApplicationContext()), “Click”, Toast.LENGTH_LONG).Display());

Update()Work);

}

});

findViewById()R.Id.button_delete).setOnClickListener()New Opinion.OnClickListener()) {{

@ Override

public Zero on click()Opinion Opinion) {{

AlertDialog.Builder Builder = = New AlertDialog.Builder()UpdateTaskActivity.this);

Builder.Satellite()“Are you sure?”);

Builder.setPositiveButton()“Yes”, New Dialog interface.OnClickListener()) {{

@ Override

public Zero on click()Dialog interface Communication thread, int I am) {{

remove()Work);

}

});

Builder.setNegativeButton()“No”, New Dialog interface.OnClickListener()) {{

@ Override

public Zero on click()Dialog interface Communication thread, int I am) {{

}

});

AlertDialog advertisement = = Builder.To create());

advertisement.Display());

}

});

}

Private Zero burden()Work Work) {{

editTextTask.Settext()Work.Gatecut()));

editTextDesc.Settext()Work.Getdesk()));

editTextFinishBy.Settext()Work.getFinishBy()));

checkBoxFinished.were set()Work.is over()));

}

Private Zero Update()The last Work Work) {{

The last String sTask = = editTextTask.Gettext()).Wire()).Trim());

The last String sDesc = = editTextDesc.Gettext()).Wire()).Trim());

The last String sFinishBy = = editTextFinishBy.Gettext()).Wire()).Trim());

If ()sTask.Is Empty())) {{

editTextTask.on the set()“Job required”);

editTextTask.request());

The return;

}

If ()sDesc.Is Empty())) {{

EditTextDesc.on the set()“Des necessary”);

EditTextDesc.request());

The return;

}

If ()sFinishBy.Is Empty())) {{

editTextFinishBy.on the set()“Finish by required”);

editTextFinishBy.request());

The return;

}

class Updatask Is spread AsyncTask<Zero, Zero, Zero> {{

@ Override

Protected Zero doInBackground()Zero... voids) {{

Work.Setscass()sTask);

Work.Setsec()sDesc);

Work.setFinishBy()sFinishBy);

Work.Determined()checkBoxFinished.is checked()));

The database.get Instance()getApplicationContext())).getAppDatabase())

.Taskdaw())

.Update()Work);

The return Invalid;

}

@ Override

Protected Zero onPostExecute()Zero aVoid) {{

Super.onPostExecute()aVoid);

Toast.Makeup()getApplicationContext()), “Updated, Toast.LENGTH_LONG).Display());

End());

Beginning()New Intent()UpdateTaskActivity.this, Main activity.class));

}

}

Updatask outside = = New Updatask());

outside.Executed());

}

Private Zero remove()The last Work Work) {{

class DeleteTask Is spread AsyncTask<Zero, Zero, Zero> {{

@ Override

Protected Zero doInBackground()Zero... voids) {{

The database.get Instance()getApplicationContext())).getAppDatabase())

.Taskdaw())

.Remove()Work);

The return Invalid;

}

@ Override

Protected Zero onPostExecute()Zero aVoid) {{

Super.onPostExecute()aVoid);

Toast.Makeup()getApplicationContext()), “is removed”, Toast.LENGTH_LONG).Display());

End());

Beginning()New Intent()UpdateTaskActivity.this, Main activity.class));

}

}

DeleteTask dt = = New DeleteTask());

dt.Executed());

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *