Sunday , October 24 2021

SQLite CRUD Example in Android using ActiveAndroid Library – Android Coding by DMTechnolab

The package The trap.Simplified coding.Activator;

Import Android.Support.v7.App.AlertDialog;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.The.Bundle;

Import Android.Opinion.Layout;

Import Android.Opinion.Opinion;

Import Android.Widget.Adapter view;

Import Android.Widget.ArrayAdapter;

Import Android.Widget.switch;

Import Android.Widget.Change in writing;

Import Android.Widget.list View;

Import Android.Widget.text view;

Import Android.Widget.Toast;

Import With.Activator.ActiveAndroid;

Import With.Activator.Query.Choose;

Import Java.Useful.array list;

Import Java.Useful.The list;

public class Main activity Is spread AppCompatActivity To apply Opinion.OnClickListener {{

// create views

Private Change in writing editTextInventoryName;

Private switch Button Seven List;

Private list View List view list;

// array list for all list collections

Private array list The list;

// Adapter for list

Private ArrayAdapter Inventory elements adapter;

@ Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.activity_main);

// initial idea

editTextInventoryName = ()Change in writing) findViewById()R.Id.editTextInventoryName);

Button Seven List = ()switch) findViewById()R.Id.Button Seven List);

List view list = ()list View) findViewById()R.Id.List view list);

// initial array list

The list = New array list());

// add listener to button

Button Seven List.setOnClickListener()this);

// calling method list to display the list

showInventoryList());

}

Private The list get all()) {{

// get all the items stored in the inventory table

The return New Choose())

.From()Inventory.class)

.order by()“Name ASC”)

.Executed());

}

Private Zero showInventoryList()) {{

// make a list and get all the inventions from the method

The list Invention = get all());

// tabulate all the items in the list by adding

For ()int I am = 0; I am < Invention.Shape()); I am++) {{

Inventory The list = Invention.get()I am);

The list.Add up()The list.Name);

}

// create our adapter

Inventory elements adapter = New ArrayAdapter()this, Android.R.Layout.simple_list_item_1, The list);

// add adapters to list

List view list.setAdapter()Inventory elements adapter);

// updating the list list

updateInventoryList());

}

Private Zero Rescuer()) {{

// Get the name from EditText

String Name = editTextInventoryName.Gettext()).Wire()).Trim());

// check if name is empty

If ()Name.equalsIgnoreCase()“”)) {{

Toast.Makeup()this, “Please enter a name”, Toast.LENGTH_LONG).Display());

The return;

}

// If the name is not empty to create a new inventory object

Inventory The list = New Inventory());

// Adding the given name to the inventory name

The list.Name = Name;

// name saving in cyclite database

The list.Save());

The list.Add up()Name);

Toast.Makeup()this, “Inventory Saved Successful”, Toast.LENGTH_LONG).Display());

}

Private Zero updateInventoryList()) {{

Inventory elements adapter.Information());

}

@ Override

public Zero on click()Opinion v) {{

Rescuer());

}

}


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 *