- steps : GO TO PROJECT > JAVA > COM......>AND CREATE PAKAGES FOR ACTIVITY,DATA BASE ,MODEL ,USER INTERFACE,UTILITIES CLASS
- GO TO NEW > LAYOUT>CREATE POPUPLIST.XML ETCCCC
- GO TO MODEL FOLDER CREATE GROCERY CLASS THE CREATE GROCERY CLASS OBJECT ITS CONSTRUCTOR AND GETTER AND SETTER METHOD
- GO TO DATA FOLDER CREATE DATABASE HANDLER ALL DATA BASE QUERIES GOES HERE >>> GO DIRECT TO UTIL
- GO TO UTIL FOLDER AND CREATE CONSTANT LIKE DATABASE NAME DATE ETC
- GO TO DATA FOLDER database hadler etcLINK ETCCCCCCC
- ANDROID MAINFEAST .XML FILE
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.gohool.mygrocerylist.mygrocerylist"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".Activities.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Activities.ListActivity" android:label="@string/title_activity_list" android:theme="@style/AppTheme.NoActionBar" /> <activity android:name=".Activities.DetailsActivity"></activity> </application> </manifest>
- MAIN ACTIVITY
package com.gohool.mygrocerylist.mygrocerylist.Activities; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.Button; import android.widget.EditText; import com.gohool.mygrocerylist.mygrocerylist.Data.DatabaseHandler; import com.gohool.mygrocerylist.mygrocerylist.Model.Grocery; import com.gohool.mygrocerylist.mygrocerylist.R; public class MainActivity extends AppCompatActivity { private AlertDialog.Builder dialogBuilder; private AlertDialog dialog; private EditText groceryItem; private EditText quantity; private Button saveButton; private DatabaseHandler db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db = new DatabaseHandler(this); byPassActivity(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)// .setAction("Action", null).show(); createPopupDialog(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private void createPopupDialog() { dialogBuilder = new AlertDialog.Builder(this); View view = getLayoutInflater().inflate(R.layout.popup, null); groceryItem = (EditText) view.findViewById(R.id.groceryItem); quantity = (EditText) view.findViewById(R.id.groceryQty); saveButton = (Button) view.findViewById(R.id.saveButton); dialogBuilder.setView(view); dialog = dialogBuilder.create(); dialog.show(); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Todo: Save to db //Todo: Go to next screen if (!groceryItem.getText().toString().isEmpty() && !quantity.getText().toString().isEmpty()) { saveGroceryToDB(v); } } }); } private void saveGroceryToDB(View v) { Grocery grocery = new Grocery(); String newGrocery = groceryItem.getText().toString(); String newGroceryQuantity = quantity.getText().toString(); grocery.setName(newGrocery); grocery.setQuantity(newGroceryQuantity); //Save to DB db.addGrocery(grocery); Snackbar.make(v, "Item Saved!", Snackbar.LENGTH_LONG).show(); // Log.d("Item Added ID:", String.valueOf(db.getGroceriesCount())); new Handler().postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); //start a new activity startActivity(new Intent(MainActivity.this, ListActivity.class)); } }, 1200); // 1 second. } public void byPassActivity() { //Checks if database is empty; if not, then we just //go to ListActivity and show all added items if (db.getGroceriesCount() > 0) { startActivity(new Intent(MainActivity.this, ListActivity.class)); finish(); } } }
- LIST ACTIVITY
package com.gohool.mygrocerylist.mygrocerylist.Activities; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import android.widget.EditText; import com.gohool.mygrocerylist.mygrocerylist.Data.DatabaseHandler; import com.gohool.mygrocerylist.mygrocerylist.Model.Grocery; import com.gohool.mygrocerylist.mygrocerylist.R; import com.gohool.mygrocerylist.mygrocerylist.UI.RecyclerViewAdapter; import java.util.ArrayList; import java.util.List; public class ListActivity extends AppCompatActivity { private RecyclerView recyclerView; private RecyclerViewAdapter recyclerViewAdapter; private List<Grocery> groceryList; private List<Grocery> listItems; private DatabaseHandler db; private AlertDialog.Builder dialogBuilder; private AlertDialog dialog; private EditText groceryItem; private EditText quantity; private Button saveButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)// .setAction("Action", null).show(); createPopDialog(); } }); db = new DatabaseHandler(this); recyclerView = (RecyclerView) findViewById(R.id.recyclerViewID); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); groceryList = new ArrayList<>(); listItems = new ArrayList<>(); // Get items from database groceryList = db.getAllGroceries(); for (Grocery c : groceryList) { Grocery grocery = new Grocery(); grocery.setName(c.getName()); grocery.setQuantity("Qty: " + c.getQuantity()); grocery.setId(c.getId()); grocery.setDateItemAdded("Added on: " + c.getDateItemAdded()); listItems.add(grocery); } recyclerViewAdapter = new RecyclerViewAdapter(this, listItems); recyclerView.setAdapter(recyclerViewAdapter); recyclerViewAdapter.notifyDataSetChanged(); } private void createPopDialog() { dialogBuilder = new AlertDialog.Builder(this); View view = getLayoutInflater().inflate(R.layout.popup, null); groceryItem = (EditText) view.findViewById(R.id.groceryItem); quantity = (EditText) view.findViewById(R.id.groceryQty); saveButton = (Button) view.findViewById(R.id.saveButton); dialogBuilder.setView(view); dialog = dialogBuilder.create(); dialog.show(); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveGroceryToDB(v); } }); } private void saveGroceryToDB(View v) { Grocery grocery = new Grocery(); String newGrocery = groceryItem.getText().toString(); String newGroceryQuantity = quantity.getText().toString(); grocery.setName(newGrocery); grocery.setQuantity(newGroceryQuantity); //Save to DB db.addGrocery(grocery); Snackbar.make(v, "Item Saved!", Snackbar.LENGTH_LONG).show(); // Log.d("Item Added ID:", String.valueOf(db.getGroceriesCount())); new Handler().postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); //start a new activity startActivity(new Intent(ListActivity.this, ListActivity.class)); finish(); } }, 1200); // 1 second. } }
- DETAIL ACTIVITY
package com.gohool.mygrocerylist.mygrocerylist.Activities; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import com.gohool.mygrocerylist.mygrocerylist.R; import org.w3c.dom.Text; public class DetailsActivity extends AppCompatActivity { private TextView itemName; private TextView quantity; private TextView dateAdded; private int groceryId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details); itemName = (TextView) findViewById(R.id.itemNameDet); quantity = (TextView) findViewById(R.id.quantityDet); dateAdded = (TextView) findViewById(R.id.dateAddedDet); Bundle bundle = getIntent().getExtras(); if ( bundle != null ) { itemName.setText(bundle.getString("name")); quantity.setText(bundle.getString("quantity")); dateAdded.setText(bundle.getString("date")); groceryId = bundle.getInt("id"); } } }
- DATABASE HANDLER
package com.gohool.mygrocerylist.mygrocerylist.Data; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.provider.SyncStateContract; import android.util.Log; import com.gohool.mygrocerylist.mygrocerylist.Model.Grocery; import com.gohool.mygrocerylist.mygrocerylist.Util.Constants; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * Created by paulodichone on 4/7/17. */ public class DatabaseHandler extends SQLiteOpenHelper { private Context ctx; public DatabaseHandler(Context context) { super(context, Constants.DB_NAME, null, Constants.DB_VERSION); this.ctx = context; } @Override public void onCreate(SQLiteDatabase db) { String CREATE_GROCERY_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "(" + Constants.KEY_ID + " INTEGER PRIMARY KEY," + Constants.KEY_GROCERY_ITEM + " TEXT," + Constants.KEY_QTY_NUMBER + " TEXT," + Constants.KEY_DATE_NAME + " LONG);"; db.execSQL(CREATE_GROCERY_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + Constants.TABLE_NAME); onCreate(db); } /** * CRUD OPERATIONS: Create, Read, Update, Delete Methods */ //Add Grocery public void addGrocery(Grocery grocery) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(Constants.KEY_GROCERY_ITEM, grocery.getName()); values.put(Constants.KEY_QTY_NUMBER, grocery.getQuantity()); values.put(Constants.KEY_DATE_NAME, java.lang.System.currentTimeMillis()); //Insert the row db.insert(Constants.TABLE_NAME, null, values); Log.d("Saved!!", "Saved to DB"); } //Get a Grocery public Grocery getGrocery(int id) { SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.query(Constants.TABLE_NAME, new String[] {Constants.KEY_ID, Constants.KEY_GROCERY_ITEM, Constants.KEY_QTY_NUMBER, Constants.KEY_DATE_NAME}, Constants.KEY_ID + "=?", new String[] {String.valueOf(id)}, null, null, null, null); if (cursor != null) cursor.moveToFirst(); Grocery grocery = new Grocery(); grocery.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(Constants.KEY_ID)))); grocery.setName(cursor.getString(cursor.getColumnIndex(Constants.KEY_GROCERY_ITEM))); grocery.setQuantity(cursor.getString(cursor.getColumnIndex(Constants.KEY_QTY_NUMBER))); //convert timestamp to something readable java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(); String formatedDate = dateFormat.format(new Date(cursor.getLong(cursor.getColumnIndex(Constants.KEY_DATE_NAME))) .getTime()); grocery.setDateItemAdded(formatedDate); return grocery; } //Get all Groceries public List<Grocery> getAllGroceries() { SQLiteDatabase db = this.getReadableDatabase(); List<Grocery> groceryList = new ArrayList<>(); Cursor cursor = db.query(Constants.TABLE_NAME, new String[] { Constants.KEY_ID, Constants.KEY_GROCERY_ITEM, Constants.KEY_QTY_NUMBER, Constants.KEY_DATE_NAME}, null, null, null, null, Constants.KEY_DATE_NAME + " DESC"); if (cursor.moveToFirst()) { do { Grocery grocery = new Grocery(); grocery.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(Constants.KEY_ID)))); grocery.setName(cursor.getString(cursor.getColumnIndex(Constants.KEY_GROCERY_ITEM))); grocery.setQuantity(cursor.getString(cursor.getColumnIndex(Constants.KEY_QTY_NUMBER))); //convert timestamp to something readable java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(); String formatedDate = dateFormat.format(new Date(cursor.getLong(cursor.getColumnIndex(Constants.KEY_DATE_NAME))) .getTime()); grocery.setDateItemAdded(formatedDate); // Add to the groceryList groceryList.add(grocery); }while (cursor.moveToNext()); } return groceryList; } //Updated Grocery public int updateGrocery(Grocery grocery) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(Constants.KEY_GROCERY_ITEM, grocery.getName()); values.put(Constants.KEY_QTY_NUMBER, grocery.getQuantity()); values.put(Constants.KEY_DATE_NAME, java.lang.System.currentTimeMillis());//get system time //update row return db.update(Constants.TABLE_NAME, values, Constants.KEY_ID + "=?", new String[] { String.valueOf(grocery.getId())} ); } //Delete Grocery public void deleteGrocery(int id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(Constants.TABLE_NAME, Constants.KEY_ID + " = ?", new String[] {String.valueOf(id)}); db.close(); } //Get count public int getGroceriesCount() { String countQuery = "SELECT * FROM " + Constants.TABLE_NAME; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); return cursor.getCount(); } }
- GRCERY
package com.gohool.mygrocerylist.mygrocerylist.Model; /** * Created by paulodichone on 4/7/17. */ public class Grocery { private String name; private String quantity; private String dateItemAdded; private int id; public Grocery() { } public Grocery(String name, String quantity, String dateItemAdded, int id) { this.name = name; this.quantity = quantity; this.dateItemAdded = dateItemAdded; this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getQuantity() { return quantity; } public void setQuantity(String quantity) { this.quantity = quantity; } public String getDateItemAdded() { return dateItemAdded; } public void setDateItemAdded(String dateItemAdded) { this.dateItemAdded = dateItemAdded; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
- RECYCLER VIEW ADAPTER
package com.gohool.mygrocerylist.mygrocerylist.UI; import android.content.Context; import android.content.Intent; import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import com.gohool.mygrocerylist.mygrocerylist.Activities.DetailsActivity; import com.gohool.mygrocerylist.mygrocerylist.Data.DatabaseHandler; import com.gohool.mygrocerylist.mygrocerylist.Model.Grocery; import com.gohool.mygrocerylist.mygrocerylist.R; import org.w3c.dom.Text; import java.util.Date; import java.util.List; /** * Created by paulodichone on 4/8/17. */ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> { private Context context; private List<Grocery> groceryItems; private AlertDialog.Builder alertDialogBuilder; private AlertDialog dialog; private LayoutInflater inflater; public RecyclerViewAdapter(Context context, List<Grocery> groceryItems) { this.context = context; this.groceryItems = groceryItems; } @Override public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_row, parent, false); return new ViewHolder(view, context); } @Override public void onBindViewHolder(RecyclerViewAdapter.ViewHolder holder, int position) { Grocery grocery = groceryItems.get(position); holder.groceryItemName.setText(grocery.getName()); holder.quantity.setText(grocery.getQuantity()); holder.dateAdded.setText(grocery.getDateItemAdded()); } @Override public int getItemCount() { return groceryItems.size(); } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public TextView groceryItemName; public TextView quantity; public TextView dateAdded; public Button editButton; public Button deleteButton; public int id; public ViewHolder(View view, Context ctx) { super(view); context = ctx; groceryItemName = (TextView) view.findViewById(R.id.name); quantity = (TextView) view.findViewById(R.id.quantity); dateAdded = (TextView) view.findViewById(R.id.dateAdded); editButton = (Button) view.findViewById(R.id.editButton); deleteButton = (Button) view.findViewById(R.id.deleteButton); editButton.setOnClickListener(this); deleteButton.setOnClickListener(this); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //go to next screen/ DetailsActivity int position = getAdapterPosition(); Grocery grocery = groceryItems.get(position); Intent intent = new Intent(context, DetailsActivity.class); intent.putExtra("name", grocery.getName()); intent.putExtra("quantity", grocery.getQuantity()); intent.putExtra("id", grocery.getId()); intent.putExtra("date", grocery.getDateItemAdded()); context.startActivity(intent); } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.editButton: int position = getAdapterPosition(); Grocery grocery = groceryItems.get(position); editItem(grocery); break; case R.id.deleteButton: position = getAdapterPosition(); grocery = groceryItems.get(position); deleteItem(grocery.getId()); break; } } public void deleteItem(final int id) { //create an AlertDialog alertDialogBuilder = new AlertDialog.Builder(context); inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.confirmation_dialog, null); Button noButton = (Button) view.findViewById(R.id.noButton); Button yesButton = (Button) view.findViewById(R.id.yesButton); alertDialogBuilder.setView(view); dialog = alertDialogBuilder.create(); dialog.show(); noButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); yesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //delete the item. DatabaseHandler db = new DatabaseHandler(context); //delete item db.deleteGrocery(id); groceryItems.remove(getAdapterPosition()); notifyItemRemoved(getAdapterPosition()); dialog.dismiss(); } }); } public void editItem(final Grocery grocery) { alertDialogBuilder = new AlertDialog.Builder(context); inflater = LayoutInflater.from(context); final View view = inflater.inflate(R.layout.popup, null); final EditText groceryItem = (EditText) view.findViewById(R.id.groceryItem); final EditText quantity = (EditText) view.findViewById(R.id.groceryQty); final TextView title = (TextView) view.findViewById(R.id.tile); title.setText("Edit Grocery"); Button saveButton = (Button) view.findViewById(R.id.saveButton); alertDialogBuilder.setView(view); dialog = alertDialogBuilder.create(); dialog.show(); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DatabaseHandler db = new DatabaseHandler(context); //Update item grocery.setName(groceryItem.getText().toString()); grocery.setQuantity(quantity.getText().toString()); if (!groceryItem.getText().toString().isEmpty() && !quantity.getText().toString().isEmpty()) { db.updateGrocery(grocery); notifyItemChanged(getAdapterPosition(),grocery); }else { Snackbar.make(view, "Add Grocery and Quantity", Snackbar.LENGTH_LONG).show(); } dialog.dismiss(); } }); } } }
- CONSTANTS
package com.gohool.mygrocerylist.mygrocerylist.Util; /** * Created by paulodichone on 4/7/17. */ public class Constants { public static final int DB_VERSION = 1; public static final String DB_NAME = "groceryListDB"; public static final String TABLE_NAME = "groceryTBL"; //Table columns public static final String KEY_ID = "id"; public static final String KEY_GROCERY_ITEM = "grocery_item"; public static final String KEY_QTY_NUMBER = "quantity_number"; public static final String KEY_DATE_NAME = "date_added"; }
- ATIVITY DETAIL XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gohool.mygrocerylist.mygrocerylist.Activities.DetailsActivity">
<android.support.v7.widget.CardView
android:layout_width="368dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent">
<RelativeLayout
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/itemNameDet"
android:text="Textview"
android:textStyle="bold"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quantityDet"
android:layout_below="@id/itemNameDet"
android:text="Qty:"
android:textStyle="italic"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/dateAddedDet"
android:layout_below="@id/quantityDet"
android:textStyle="italic"
android:textSize="14sp"
android:text="Date:"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TableRow
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:layout_alignBottom="@id/dateAddedDet"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="@+id/editButtonDet"
android:layout_width="30dp"
android:layout_marginRight="15dp"
android:layout_height="30dp"
android:background="@android:drawable/ic_menu_edit"/>
<Button android:id="@+id/deleteButtonDet"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@android:drawable/ic_delete"/>
</TableRow>
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
- ACTIVITY LIST XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gohool.mygrocerylist.mygrocerylist.Activities.ListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_list" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add" />
</android.support.design.widget.CoordinatorLayout>
- ACTIVITY MAIN
- CONFORMATION DIALOG
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gohool.mygrocerylist.mygrocerylist.Activities.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:padding="23dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/textAlert"
android:text="@string/sure_text"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="5dp"
android:textSize="17sp"
android:textStyle="bold"
android:layout_height="wrap_content" />
<Button
android:id="@+id/noButton"
android:background="@color/colorAccent"
android:text="@string/no"
android:layout_marginTop="19dp"
android:layout_below="@id/textAlert"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/yesButton"
android:layout_alignParentRight="true"
android:text="@string/yes"
android:background="@color/colorAccent"
android:layout_alignBottom="@id/noButton"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
- CONTENT LIST
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.gohool.mygrocerylist.mygrocerylist.Activities.ListActivity"
tools:showIn="@layout/activity_list">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewID"
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
- CONTENT MAIN
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.gohool.mygrocerylist.mygrocerylist.Activities.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/add_item"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.558" />
</android.support.constraint.ConstraintLayout>
- LIST ROW XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:padding="15dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/name"
android:text="Groceryname"
android:textSize="18sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quantity"
android:layout_below="@id/name"
android:text="Qty"
android:paddingTop="5dp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/dateAdded"
android:paddingTop="5dp"
android:text="Date:"
android:textStyle="italic"
android:layout_below="@id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TableRow
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:layout_alignBottom="@id/dateAdded"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="@+id/editButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="15dp"
android:background="@android:drawable/ic_menu_edit"/>
<Button
android:id="@+id/deleteButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@android:drawable/ic_delete"/>
</TableRow>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
- POPUP XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tile"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:textStyle="italic"
android:textSize="18sp"
android:text="@string/enter_item"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/groceryItem"
android:layout_below="@id/tile"
android:layout_width="match_parent"
android:hint="@string/hint_item"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/groceryQty"
android:layout_below="@id/groceryItem"
android:hint="@string/quantity_hint"
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/saveButton"
android:layout_marginTop="5dp"
android:layout_below="@id/groceryQty"
android:text="@string/save_title"
android:textStyle="bold"
android:textColor="@android:color/white"
android:background="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>