Skip to content

Commit

Permalink
file added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul255 committed Jul 1, 2019
1 parent d3ea489 commit c3e90b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public boolean updateData(String id, String name, String surname, String marks)
db.update(TABLE_NAME, contentvalues, "ID = ?",new String[] {id});
return true;
}
public Integer deleteData (String id){
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME,"ID = ?",new String[] {id});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MainActivity extends AppCompatActivity {
Button btnAddData;
Button btnviewAll;
Button btnviewUpdate;
Button btnDelete;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -30,9 +31,25 @@ protected void onCreate(Bundle savedInstanceState) {
btnAddData=findViewById(R.id.button_add);
btnviewAll=findViewById(R.id.button_view);
btnviewUpdate=findViewById(R.id.button_update);
btnDelete=findViewById(R.id.button_delete);
AddData();
viewAll();
UpdateData();
DeleteData();
}
public void DeleteData(){
btnDelete.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer deletedRows = myDb.deleteData(editTextId.getText().toString());
if(deletedRows > 0)
Toast.makeText(MainActivity.this,"Data Deleted",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Deleted",Toast.LENGTH_LONG).show();
}
}
);
}

public void UpdateData(){
Expand Down
7 changes: 7 additions & 0 deletions AndroDatabase/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
android:text="Update"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="261dp" />
<Button
android:id="@+id/button_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="261dp" />
</LinearLayout>


Expand Down

0 comments on commit c3e90b5

Please sign in to comment.