이번 수업을 통해 지난 SharedPreference를 이용한 데이터 저장방식과 다른 이번엔 DBLite를 이용한 데이터 관리를 해볼 것이다.
지난 SP와는 다르게 DB 쿼리문도 알아야하고 접근 방식도 다르나, 결과적으로 범용적인 DB에 접근하는 방법을 익히게 될 것이다.
우선 식단관리 어플은 해당 날짜, 아침, 점심, 저녁, 음식, 각 음식의 칼로리 데이터 등 관리해야할 데이터들 이 지난 수업 때 만들었던 것들보다 많다.
이번 어플을 제작하면서 프론트엔드도 신경써보느라, 여러 xml파일의 폰트 및 drawable로 레이아웃의 테투리 및 디테일도 한 번 나름 신경써보았다. 아직 허접하지만 접근 방식을 알았다는 것에 의의를 두겠다.
스플래시 먼저 보자,
스플래시는 어플의 첫인상이라 나름 신중하게 깔끔한 이미지를 구글링해서 찾아서 사용하였다.
스플래시 부분은 지난 시간에 했던 부분과 동일하니 넘어가겠다. 소스코드는 다음과 같다.
(시간은 3초 너무길다는 피드백을 받았기에 1.5초로 줄임)
SplashActivity.java
package com.daniel.app.sqlite_demo;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
//초기화면
@Override
protected void onCreate(Bundle savedInstanceStare) {
super.onCreate(savedInstanceStare);
setContentView(R.layout.activity_splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
}
},1500);
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
activity_splach.xml
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splashopening"/>
메인, 이번 어플에서 메인 액티비티는 각 원하는 메뉴에 접근하기 위한 하나의 페이지로서 큰 기능은 없다.
1. 하단메뉴바를 적용해 각 액티비티로의 접근을 좀 깔끔하게 해줌 - fragment를 이용한 접근을 하는게 좋아보이나, 사실 기능면을 모두 만들어두고 나중에 입히느라 fragment적용하는게 만만치 않게되어 인텐트를 이용한 이동을 하고, 하단메뉴바의 클릭 기능만 이용함
MainActivity.java
package com.daniel.app.sqlite_demo;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
Context mContext;
Fragment1 fragment1;
private FragmentManager fragmentManager = getSupportFragmentManager();
BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_main);
bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
fragment1 = new Fragment1();
//이부분 나중에 물어볼것
//getSupportFragmentManager().beginTransaction().replace(R.layout.activity_main,fragment1).commitAllowingStateLoss();
RecyclerViewAdapter.fromwhere = "foodactivity";
//하단 메뉴바
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@SuppressLint("ResourceType")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
//getSupportFragmentManager().beginTransaction().replace(R.layout.activity_main,fragment1).commitAllowingStateLoss();
//return true;
Intent goto_insert = new Intent(MainActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(MainActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(MainActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(MainActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
//뒤로가기 버튼
@Override
public void onBackPressed() {
moveTaskToBack(true);
finish();
}
}
activity_main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
식단 데이터(리사이클러뷰) 액티비티
리사이클러뷰와 ArrayList를 Adapter를 이용해 연동한 후 뷰를 이용해 띄우고, 데이터 삽입부분은 카카오톡의 + 부분을 따라해 보았다
FoodActivity.java
package com.daniel.app.sqlite_demo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.util.ArrayList;
public class FoodActicity extends AppCompatActivity {
//변수 선언
Context mcontext;
SQLiteDatabase msqLiteDatabase;
DbHelper mdbhelper;
Button mInsert;
String mwhen;
String mid_fromSearch;
RecyclerView mrecyclerView;
ArrayList mfoodItemList = new ArrayList<>();
ArrayList mmodifiedList = new ArrayList<>();
RecyclerView.Adapter mrecyclerViewAdapter;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_food_acticity);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
mrecyclerView = (RecyclerView) findViewById(R.id.rv_view);
mInsert = findViewById(R.id.insert);
//추가, 수정, 삭제 시에 해당 recyclerview의 크기 높이 변경 방지
mrecyclerView.setHasFixedSize(true);
//데이터 초기화
mfoodItemList.clear();
//DB헬퍼 생성
mdbhelper = new DbHelper(this);
//DB에 오픈헬퍼를 이용해 데이터 입력
msqLiteDatabase = mdbhelper.getReadableDatabase();
//트랜잭션 시작.
msqLiteDatabase.beginTransaction();
//검색 액티비티와 데이터 연동 인텐트
Intent fromsearch = getIntent();
//식단 식별
mwhen = fromsearch.getStringExtra("when");
//DB접근용 id
mid_fromSearch = fromsearch.getStringExtra("id");
//인텐트 null검사 -> 안하면 ArrayList가 nullpointerExeption 됨
if ((ArrayList<FoodItem>) fromsearch.getSerializableExtra("list") != null) {
mmodifiedList = (ArrayList<FoodItem>) fromsearch.getSerializableExtra("list");
}
//DB의 데이터 불러와 ArrayList에 저장
Cursor cursor = mdbhelper.LoadSQLiteDBCursor();
try {
cursor.moveToFirst();
System.out.println("SQLiteDB 개수 = " + cursor.getCount());
//커서에 데이터 저장
while (!cursor.isAfterLast()) {
addGroupItem(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
cursor.moveToNext();
}
msqLiteDatabase.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
msqLiteDatabase.endTransaction();
}
}
//리싸이클러뷰 레이아웃매니저
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mrecyclerView.setLayoutManager(layoutManager);
//어댑터 연결
mrecyclerViewAdapter = new RecyclerViewAdapter(mfoodItemList, this);
mrecyclerView.setAdapter(mrecyclerViewAdapter);
//버튼 클릭 이벤트
mInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent goto_edit = new Intent(FoodActicity.this, FoodNewActivity.class);
startActivity(goto_edit);
finish();
}
});
//하단메뉴바 클릭 이벤트
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(FoodActicity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(FoodActicity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(FoodActicity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(FoodActicity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
//뒤로가기시 메인으로 가고 finish
@Override
public void onBackPressed() {
Intent intent = new Intent(FoodActicity.this, MainActivity.class);
startActivity(intent);
finish();
}
//DB의 id값 어댑터로 넘겨주기
public String setid() {
return mid_fromSearch;
}
public String setwhen() {
return mwhen;
}
//데이터 수정시 어레이에 담는 함수
public void setlist(String when, String food_name, String food_kcal) {
FoodItem item = new FoodItem();
item.setTitle(food_name);
item.setDetail(food_kcal);
if (when.equals("breakfast")) {
mmodifiedList.set(0, item);
} else if (when.equals("lunch")) {
mmodifiedList.set(1, item);
} else if (when.equals("dinner")) {
mmodifiedList.set(2, item);
}
}
//수정된 데이터 어레이 받아가는 함수
public ArrayList<FoodItem> getlist() {
return mmodifiedList;
}
//DB에서 가져온 데이터 Arraylist에 담는 함수
public void addGroupItem(Long uid, String title, String detail) {
FoodItem item = new FoodItem();
item.setUid(uid);
item.setTitle(title);
item.setDetail(detail);
mfoodItemList.add(item);
}
}
activity_food_activity.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/insert"
android:layout_width="72dp"
android:layout_height="70dp"
android:layout_above="@+id/bottom_Navigation_View"
android:layout_gravity="right|bottom"
android:layout_marginRight="20dp"
android:layout_marginBottom="70dp"
android:background="@drawable/corner"
android:text="+"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="30sp" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
리스트 액티비티에는 데이터 삽입 액티비티로 이동이 가능한데, 이를 이용해 식단(음식의 종류와 칼로리) 추가 할 수 있다.
activity_food_new.xml
<LinearLayout 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=".FoodEditActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="식단 추가"
android:fontFamily="@font/hoonddukbokki"
android:textSize="50sp"
android:layout_margin="20dp"
android:textColor="#000000"
android:layout_gravity="center"
/>
<EditText
android:id="@+id/et_new_title"
android:hint="음식명을 입력하세요"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"/>
<EditText
android:id="@+id/et_new_contents"
android:hint="칼로리를 입력하세요"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"/>
<Button
android:id="@+id/btn_edit_new_complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@drawable/button"
android:textColor="#000000"
android:layout_margin="20dp"
android:textSize="20sp"
android:text="완료" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
FoodNewActivity.java
package com.daniel.app.sqlite_demo;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class FoodNewActivity extends AppCompatActivity {
SQLiteDatabase mdb;
DbHelper mDbHelper;
EditText mtitle;
EditText mcontents;
Button mComplete;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_food_new);
mtitle = findViewById(R.id.et_new_title);
mcontents = findViewById(R.id.et_new_contents);
mComplete = findViewById(R.id.btn_edit_new_complete);
//DB 접근
mDbHelper = new DbHelper(this);
mdb = mDbHelper.getWritableDatabase();
//신규 데이터 DB에 저장
mComplete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentValues contentValues = new ContentValues();
String title = mtitle.getText().toString();
String contents = mcontents.getText().toString();
contentValues.put(mDbHelper.TITLE, title);
contentValues.put(mDbHelper.DETAIL, contents);
//데이터 삽입 쿼리
mdb.insert(mDbHelper.TABLE_NAME, null, contentValues);
Intent openMainScreen = new Intent(FoodNewActivity.this, FoodActicity.class);
startActivity(openMainScreen);
finish();
}
});
//하단 메뉴바
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(FoodNewActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(FoodNewActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(FoodNewActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(FoodNewActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
}
데이터 접근, 수정 및 삭제 기능도 물론 가능하다.
activity_food_view.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="식단 정보"
android:fontFamily="@font/hoonddukbokki"
android:textSize="50sp"
android:layout_margin="20dp"
android:textColor="#000000"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/food_view_title"
android:text="이름"
android:textColor="#000000"
android:layout_margin="30dp"
android:textSize="30sp"
android:fontFamily="@font/hoonddukbokki"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:background="#4682B4" />
<TextView
android:id="@+id/food_view_contents"
android:text="내용"
android:textColor="#000000"
android:layout_margin="30dp"
android:textSize="30sp"
android:fontFamily="@font/hoonddukbokki"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:background="#4682B4" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right">
<Button
android:id="@+id/food_view_modify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/hoonddukbokki"
android:background="@drawable/button"
android:textColor="#000000"
android:textSize="20sp"
android:layout_gravity="right|center"
android:text="수정" />
<Button
android:id="@+id/food_view_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/hoonddukbokki"
android:background="@drawable/button"
android:textColor="#000000"
android:textSize="20sp"
android:layout_gravity="right|center"
android:text="삭제"/>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
activity_food_edit.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="식단 수정"
android:fontFamily="@font/hoonddukbokki"
android:textSize="50sp"
android:textColor="#000000"
android:layout_gravity="center"
android:layout_margin="20dp"/>
<EditText
android:id="@+id/et_food_view_title"
android:hint="음식명을 입력하세요"
android:layout_width="match_parent"
android:fontFamily="@font/hoonddukbokki"
android:layout_margin="20dp"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/et_food_contents"
android:hint="칼로리를 입력하세요"
android:layout_width="match_parent"
android:fontFamily="@font/hoonddukbokki"
android:layout_margin="20dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_edit_food_complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:layout_gravity="right"
android:textColor="#000000"
android:layout_margin="20dp"
android:text="완료"
android:textSize="20sp" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
FoodViewActivity.java
package com.daniel.app.sqlite_demo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class FoodViewActivity extends AppCompatActivity {
SQLiteDatabase mdb;
DbHelper mdbHelper;
Button mFoodViewDelete;
Button mFoodViewModify;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_food_view);
mFoodViewDelete = findViewById(R.id.food_view_delete);
mFoodViewModify = findViewById(R.id.food_view_modify);
mdbHelper = new DbHelper(this);
mdb = mdbHelper.getWritableDatabase();
TextView title = findViewById(R.id.food_view_title);
TextView detail = findViewById(R.id.food_view_contents);
//DB id 값 인텐트
final long id = getIntent().getExtras().getLong(getString(R.string.row_id));
//id값에 해당하는 row 접근 쿼리
Cursor cursor = mdb.rawQuery("select * from " + mdbHelper.TABLE_NAME + " where " + mdbHelper.C_ID + "=" + id, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
title.setText(cursor.getString(cursor.getColumnIndex(mdbHelper.TITLE)));
detail.setText(cursor.getString(cursor.getColumnIndex(mdbHelper.DETAIL)) + " kcal");
}
cursor.close();
}
//수정 액티비티로 이동 인텐트
mFoodViewModify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent goto_edit = new Intent(FoodViewActivity.this, FoodEditActivity.class);
goto_edit.putExtra("rowID", id);
finish();
startActivity(goto_edit);
}
});
//DB에서 데이터 삭제
mFoodViewDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//데이터 삭제 쿼리
mdb.delete(DbHelper.TABLE_NAME, DbHelper.C_ID + "=" + id, null);
Intent openMainActivity = new Intent(FoodViewActivity.this, MainActivity.class);
mdb.close();
finish();
startActivity(openMainActivity);
}
});
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(FoodViewActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(FoodViewActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(FoodViewActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(FoodViewActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
//뒤로가기 버튼
@Override
public void onBackPressed() {
Intent setIntent = new Intent(this, MainActivity.class);
startActivity(setIntent);
}
}
FoodEditActivity.java
package com.daniel.app.sqlite_demo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.material.bottomnavigation.BottomNavigationView;
//식단 리스트 수정 액티비티
public class FoodEditActivity extends AppCompatActivity {
SQLiteDatabase mdb;
DbHelper mDbHelper;
EditText mtitle;
EditText mcontents;
Button mComplete;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_food_edit);
mtitle = findViewById(R.id.et_food_view_title);
mcontents = findViewById(R.id.et_food_contents);
mComplete = findViewById(R.id.btn_edit_food_complete);
//인텐트 DB id 값 받아오기
final long id = getIntent().getExtras().getLong(getString(R.string.row_id));
//DB 불러오기
mDbHelper = new DbHelper(this);
mdb =mDbHelper.getWritableDatabase();
Cursor cursor = mdb.rawQuery("select * from " + mDbHelper.TABLE_NAME + " where " + mDbHelper.C_ID + "=" + id, null);
//선택된 식단 불러오기
if (cursor != null) {
if (cursor.moveToFirst()) {
mtitle.setText(cursor.getString(cursor.getColumnIndex(mDbHelper.TITLE)));
mcontents.setText(cursor.getString(cursor.getColumnIndex(mDbHelper.DETAIL)));
}
cursor.close();
}
//수정된 데이터 DB에 저장하는 클릭리스너
mComplete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentValues contentValues = new ContentValues();
String title = mtitle.getText().toString();
String contents = mcontents.getText().toString();
contentValues.put(mDbHelper.TITLE, title);
contentValues.put(mDbHelper.DETAIL, contents);
//업데이트 쿼리
mdb.update(mDbHelper.TABLE_NAME,contentValues,mDbHelper.C_ID+"="+id,null);
Intent openMainScreen = new Intent(FoodEditActivity.this, FoodActicity.class);
finish();
startActivity(openMainScreen);
}
});
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//이건 안쓰긴하는데 물어보기 위해 남겨두자
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(FoodEditActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(FoodEditActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(FoodEditActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(FoodEditActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
}
각 리스트의 모양을 테두리를 만들고 모서리를 둥글게 만들고 색을 좀 바꿔 나름 꾸며보았다
FoodItem.java
package com.daniel.app.sqlite_demo;
import java.io.Serializable;
public class FoodItem implements Serializable {
private Long uid;
private String title; // 식단이름
private String detail; // 칼로리
public FoodItem() {
}
public FoodItem(Long uid, String title, String detail) {
this.uid = uid;
this.title = title;
this.detail = detail;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
}
food_item.xml
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="음식 이름"
android:textColor="#000000"
android:fontFamily="@font/hoonddukbokki"
android:textSize="20sp"
android:layout_margin="10sp"/>
<View
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:background="#4682B4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text=" kcal"
android:textColor="#000000"
android:textSize="20sp"
android:layout_margin="10sp"/>
다음은 하단메뉴의다른접근인 식단 다이어리추가 페이지
해당 페이지도 나름 신경을 많이 쓴 페이지이다 한페이지에서 캘린더뷰를 이용해 날짜를 입력받고, 식사 시간을 입력받으며, 해당 음식리스트를 입력받는 한 페이지에 모든걸 하는 올인원을 해보느라 정성을 쏟은 페이지. 하지만 검색페이지가 더 정성을 쏟았다.
InsertActivity.java
package com.daniel.app.sqlite_demo;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.util.ArrayList;
public class InsertActivity extends AppCompatActivity {
Context mcontext;
SQLiteDatabase msqLiteDatabase;
DbHelper mdbhelper;
DbHelper_calendar mDbHelper_calendar;
Spinner mspinner;
ArrayList<FoodItem> mfoodItemList = new ArrayList<>();
RecyclerView.Adapter mrecyclerViewAdapter;
Button mbtnEnd, mlistBtn;
CalendarView mcalView;
RecyclerView mrecyclerView;
TextView mtvYear, mtvMonth, mtvDay, mtvtitle, mtvcontents, mtvwhen;
int mselectYear, mselectMonth, mselectDay;
Long muid;
String mtitle;
String mcontents;
String mwhen;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_insert);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
mbtnEnd = findViewById(R.id.btnEnd);
mrecyclerView = findViewById(R.id.rv_view);
mcalView = findViewById(R.id.calendarView1);
mtvYear = findViewById(R.id.tvYear);
mtvMonth = findViewById(R.id.tvMonth);
mtvDay = findViewById(R.id.tvDay);
mtvtitle = findViewById(R.id.tvtitle);
mtvcontents = findViewById(R.id.tvcontents);
mtvwhen = findViewById(R.id.when);
mspinner = findViewById(R.id.spinner);
//어댑터 연결
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.when, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mspinner.setAdapter(adapter);
//추가, 수정, 삭제 시에 해당 recyclerview의 크기 높이 변경 방지
mrecyclerView.setHasFixedSize(true);
//데이터 초기화
mfoodItemList.clear();
//DB헬퍼 생성
mdbhelper = new DbHelper(this);
//DB에 오픈헬퍼를 이용해 데이터 입력
msqLiteDatabase = mdbhelper.getReadableDatabase();
//트랜잭션 시작.
msqLiteDatabase.beginTransaction();
Cursor cursor = mdbhelper.LoadSQLiteDBCursor();
try {
cursor.moveToFirst();
System.out.println("SQLiteDB 개수 = " + cursor.getCount());
//커서에 데이터 저장
while (!cursor.isAfterLast()) {
addGroupItem(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
cursor.moveToNext();
}
msqLiteDatabase.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
msqLiteDatabase.endTransaction();
}
}
//리사이클러뷰 레이아웃 매니져
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mrecyclerView.setLayoutManager(layoutManager);
//어댑터 연결
mrecyclerViewAdapter = new RecyclerViewSelectionAdapter(mfoodItemList, this);
mrecyclerView.setAdapter(mrecyclerViewAdapter);
//두번째 테이블 접근
mDbHelper_calendar = new DbHelper_calendar(this);
msqLiteDatabase = mDbHelper_calendar.getWritableDatabase();
//차례로 보이지 안보이기
mspinner.setVisibility(View.INVISIBLE);
mrecyclerView.setVisibility(View.VISIBLE);
mcalView.setVisibility(View.INVISIBLE);
//날짜 선택시 달력 사라지고 스피너 visible
mcalView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
mselectYear = year;
mselectMonth = month + 1;
mselectDay = dayOfMonth;
mcalView.setVisibility(View.INVISIBLE);
mspinner.setVisibility(View.VISIBLE);
mtvYear.setText("0" + mselectYear);
mtvMonth.setText("0" + mselectMonth);
mtvDay.setText("0" + mselectDay);
}
});
//아침,점심,저녁 선택 스피너
mspinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mwhen = (String) mspinner.getItemAtPosition(position);
mspinner.setVisibility(View.INVISIBLE);
mtvwhen.setText(mwhen);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(InsertActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(InsertActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(InsertActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(InsertActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
//완료버튼 클릭시, 데이터 받아와서 DB에 넣음
mbtnEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentValues contentValues = new ContentValues();
contentValues.put(mDbHelper_calendar.YEAR, mselectYear);
contentValues.put(mDbHelper_calendar.MONTH, mselectMonth);
contentValues.put(mDbHelper_calendar.DATE, mselectDay);
if (mwhen.equals("breakfast")) {
System.out.println("아침" + mtitle + mcontents);
contentValues.put(mDbHelper_calendar.BREAKFAST, mtitle);
contentValues.put(mDbHelper_calendar.BREAKFAST_KCAL, mcontents);
} else if (mwhen.equals("lunch")) {
System.out.println("점심" + mtitle + mcontents);
contentValues.put(mDbHelper_calendar.LUNCH, mtitle);
contentValues.put(mDbHelper_calendar.LUNCH_KCAL, mcontents);
} else if (mwhen.equals("dinner")) {
System.out.println("저녁" + mtitle + mcontents);
contentValues.put(mDbHelper_calendar.DINNER, mtitle);
contentValues.put(mDbHelper_calendar.DINNER_KCAL, mcontents);
}
//데이터 삽입 쿼리
msqLiteDatabase.insert(mDbHelper_calendar.TABLE_NAME, null, contentValues);
//DB 닫아주기
msqLiteDatabase.close();
Intent intent = new Intent(InsertActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
//뒤로가기 버튼
@Override
public void onBackPressed() {
Intent intent = new Intent(InsertActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
//DB에서 불러온 데이터 삽입 함수
public void addGroupItem(Long uid, String title, String detail) {
FoodItem item = new FoodItem();
item.setUid(uid);
System.out.println("유아이디" + uid);
item.setTitle(title);
item.setDetail(detail);
mfoodItemList.add(item);
}
//어댑터와 데이터 연동
public void getListItem(Long uid, String title, String detail) {
this.muid = uid;
this.mtitle = title;
this.mcontents = detail;
}
}
activity_insert.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="식단 기록하기"
android:fontFamily="@font/hoonddukbokki"
android:textColor="#000000"
android:textSize="30sp"
android:layout_margin="30dp"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<CalendarView
android:id="@+id/calendarView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:showWeekNumber="false"/>
<Spinner
android:id="@+id/spinner"
android:entries="@array/when"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:layout_gravity="center"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_view"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tvYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="0000"
android:textColor="#000000"
android:textSize="40sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="년 "
android:textColor="#000000"
android:textSize="40sp"/>
<TextView
android:id="@+id/tvMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="00"
android:textColor="#000000"
android:textSize="40sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="월 "
android:textColor="#000000"
android:textSize="40sp"/>
<TextView
android:id="@+id/tvDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="00"
android:textColor="#000000"
android:textSize="40sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="일"
android:textColor="#000000"
android:textSize="40sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/when"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="00"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text=" : "
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:id="@+id/tvtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:text="00"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text=" , "
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:id="@+id/tvcontents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="00"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonddukbokki"
android:text="kcal"
android:textColor="#000000"
android:textSize="30sp"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<Button
android:id="@+id/btnEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:layout_gravity="center"
android:textColor="#000000"
android:textSize="20sp"
android:fontFamily="@font/hoonddukbokki"
android:text="기록하기"
android:layout_marginBottom="50dp"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
다음은 식단다이어리를 캘린더뷰로 날짜를 입력받아 DB쿼리로 데이터에 접근, 수정 및 삭제가 가능하게 하였다.
디테일하게 기능면을 몇가지 수정하였는데, 캘린더뷰의 날짜를 클릭할 때마다 저장된 데이터를 볼 수 있도록 구현하였고
수정페이지로 이동한 후, 여러번의 여러종류의 수정을 거치더라도 수정된 데이터 묶음을 arraylist에 넣어 Intent로 넘기기때문에 좀 더 사용자입장에서 자유로운 데이터 수정이 가능하다.
SearchActivity.java
package com.daniel.app.sqlite_demo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class SearchActivity extends AppCompatActivity {
SQLiteDatabase mdb;
DbHelper_calendar mDbHelper_calendar;
Button mmodify;
Button mdelete;
TextView mtv_breakfast;
TextView mtv_breakfast_kcal;
TextView mtv_lunch;
TextView mtv_lunch_kcal;
TextView mtv_dinner;
TextView mtv_dinner_kcal;
TextView mtv_total_kcal;
CalendarView mcalView;
String muid;
String med_year;
String med_month;
String med_day;
String mbreakfast;
String mbreakfast_kcal;
String mlunch;
String mlunch_kcal;
String mdinner;
String mdinner_kcal;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_search);
mmodify = findViewById(R.id.search_modify);
mdelete = findViewById(R.id.search_delete);
mcalView = findViewById(R.id.calendarView);
mtv_breakfast = findViewById(R.id.result_breakfast);
mtv_breakfast_kcal = findViewById(R.id.result_breakfast_kcal);
mtv_lunch = findViewById(R.id.result_lunch);
mtv_lunch_kcal = findViewById(R.id.result_lunch_kcal);
mtv_dinner = findViewById(R.id.result_dinner);
mtv_dinner_kcal = findViewById(R.id.result_dinner_kcal);
mtv_total_kcal = findViewById(R.id.result_total_kcal);
//하단 메뉴바
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
//디비 연동
mDbHelper_calendar = new DbHelper_calendar(this);
mdb =mDbHelper_calendar.getWritableDatabase();
//캘린더뷰를 이용한 년,월,일 데이터 받아오기
mcalView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
med_year = String.valueOf(year);
med_month = String.valueOf(month+1);
med_day = String.valueOf(dayOfMonth);
//날짜 클릭시마다 새로운 데이터를 보여주기 위한 초기화
muid = null;
mbreakfast = null;
mbreakfast_kcal = null;
mlunch = null;
mlunch_kcal = null;
mdinner = null;
mdinner_kcal = null;
//년,월,일을 이용한 DB 조건(where) 쿼리
Cursor cursor = mdb.rawQuery("select * from " + mDbHelper_calendar.TABLE_NAME + " where " + mDbHelper_calendar.YEAR + "='" + med_year + "' and " + mDbHelper_calendar.MONTH + "='" + med_month + "' and " + mDbHelper_calendar.DATE + "='" + med_day +"'", null);
if (cursor != null) {
if (cursor.moveToFirst()) {
muid = cursor.getString(cursor.getColumnIndex("_id"));
mbreakfast = cursor.getString(cursor.getColumnIndex("breakfast"));
mbreakfast_kcal = cursor.getString(cursor.getColumnIndex("breakfast_kcal"));
mlunch = cursor.getString(cursor.getColumnIndex("lunch"));
mlunch_kcal = cursor.getString(cursor.getColumnIndex("lunch_kcal"));
mdinner = cursor.getString(cursor.getColumnIndex("dinner"));
mdinner_kcal = cursor.getString(cursor.getColumnIndex("dinner_kcal"));
}
cursor.close();
}
//화면에 null로 나오는 부분 0kcal로 보이도록 수정
if(mbreakfast_kcal==null){mbreakfast_kcal="0";}
if(mlunch_kcal==null){mlunch_kcal="0";}
if(mdinner_kcal==null){mdinner_kcal="0";}
//kcal 뒤에 추가
mtv_breakfast.setText(mbreakfast);
mtv_breakfast_kcal.setText(mbreakfast_kcal+" kcal");
mtv_lunch.setText(mlunch);
mtv_lunch_kcal.setText(mlunch_kcal+" kcal");
mtv_dinner.setText(mdinner);
mtv_dinner_kcal.setText(mdinner_kcal+" kcal");
//string -> integer로 변경하여 total kcal 계산
int breakfastkcal = 0;
if(mbreakfast_kcal !=null){
breakfastkcal = Integer.parseInt(mbreakfast_kcal);}
int lunchkcal = 0;
if(mlunch_kcal !=null){
lunchkcal = Integer.parseInt(mlunch_kcal);}
int dinnerkcal = 0;
if(mdinner_kcal !=null){
dinnerkcal = Integer.parseInt(mdinner_kcal);}
mtv_total_kcal.setText(String.valueOf(breakfastkcal+lunchkcal+dinnerkcal)+" kcal");
}
});
//수정 액티비티로 이동 클릭리스너
mmodify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SearchActivity.this, SearchModifyActivity.class);
//해당 날짜에 데이터 없을 시 경고창 띄우기
if(mbreakfast==null&&mlunch==null&&mdinner==null){
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setTitle("식단 없음").setMessage("해당 날짜에 등록된 식단이 없습니다.");
AlertDialog alertDialog = builder.create();
alertDialog.show();
}else{
//수정 페이지로 데이터 보내기
mdb.close();
intent.putExtra("id", muid);
intent.putExtra("year", med_year);
intent.putExtra("month", med_month);
intent.putExtra("day", med_day);
intent.putExtra("breakfast", mbreakfast);
intent.putExtra("breakfast_kcal", mbreakfast_kcal);
intent.putExtra("lunch", mlunch);
intent.putExtra("lunch_kcal", mlunch_kcal);
intent.putExtra("dinner", mdinner);
intent.putExtra("dinner_kcal", mdinner_kcal);
startActivity(intent);}
}
});
//삭제 클릭리스너
mdelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//DB 삭제 쿼리
mdb.delete(DbHelper_calendar.TABLE_NAME, DbHelper_calendar.C_ID + "='" + muid +"'", null);
//메인으로 이동하고 finish, 액티비티 관리
Intent openMainActivity = new Intent(SearchActivity.this, MainActivity.class);
mdb.close();
finish();
startActivity(openMainActivity);
}
});
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(SearchActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(SearchActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(SearchActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(SearchActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
//뒤로가기 버튼
@Override
public void onBackPressed(){
Intent intent = new Intent(SearchActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
activity_search.xml
<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showWeekNumber="false"/>
<TextView
android:id="@+id/result_breakfast_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:text="아침" />
<TextView
android:id="@+id/result_breakfast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
<TextView
android:id="@+id/result_breakfast_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/result_lunch_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#000000"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:fontFamily="@font/sangsangflowerroad"
android:text="점심"
/>
<TextView
android:id="@+id/result_lunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
<TextView
android:id="@+id/result_lunch_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/result_dinner_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:textColor="#000000"
android:textSize="25sp"
android:fontFamily="@font/sangsangflowerroad"
android:text="저녁" />
<TextView
android:id="@+id/result_dinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
<TextView
android:id="@+id/result_dinner_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="25sp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TOTAL = "
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:layout_marginLeft="20dp"
android:textSize="30sp"/>
<TextView
android:id="@+id/result_total_kcal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:textSize="30sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:id="@+id/search_modify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="수정"
android:background="@drawable/button"
android:textColor="#000000"
android:layout_margin="10dp"
android:textSize="20sp"
/>
<Button
android:id="@+id/search_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:textColor="#000000"
android:layout_margin="10dp"
android:textSize="20sp"
android:text="삭제"/>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
SearchModiftActivity.java
package com.daniel.app.sqlite_demo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.util.ArrayList;
public class SearchModifyActivity extends AppCompatActivity {
TextView mtv_year;
TextView mtv_month;
TextView mtv_day;
TextView mtv_breakfast;
TextView mtv_breakfast_kcal;
TextView mtv_lunch;
TextView mtv_lunch_kcal;
TextView mtv_dinner;
TextView mtv_dinner_kcal;
Button mbtn_breakfast;
Button mbtn_lunch;
Button mbtn_dinner;
Button mbtn_complete;
ArrayList<FoodItem> mdata = new ArrayList<FoodItem>();
FoodItem item = new FoodItem();
String mwhen;
String mid;
SQLiteDatabase mdb;
DbHelper_calendar mDbHelper_calendar;
private FragmentManager fragmentManager = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//뷰 연결
setContentView(R.layout.activity_search_modify);
mtv_year = findViewById(R.id.search_modify_year);
mtv_month = findViewById(R.id.search_modify_month);
mtv_day = findViewById(R.id.search_modify_day);
mtv_breakfast = findViewById(R.id.search_modify_breakfast);
mtv_breakfast_kcal = findViewById(R.id.search_modify_breakfast_kcal);
mtv_lunch = findViewById(R.id.search_modify_lunch);
mtv_lunch_kcal = findViewById(R.id.search_modify_lunch_kcal);
mtv_dinner = findViewById(R.id.search_modify_dinner);
mtv_dinner_kcal = findViewById(R.id.search_modify_dinner_kcal);
mbtn_breakfast = findViewById(R.id.search_modify_breakfast_btn);
mbtn_lunch = findViewById(R.id.search_modify_lunch_btn);
mbtn_dinner = findViewById(R.id.search_modify_dinner_btn);
mbtn_complete = findViewById(R.id.search_modify_complete);
//인텐트 받아오기
Intent modify = getIntent();
//DB 연결
mDbHelper_calendar = new DbHelper_calendar(this);
mdb =mDbHelper_calendar.getReadableDatabase();
final Intent fromAdapter = getIntent();
mid = modify.getStringExtra("id");
//id값을 이용한 데이터 접근 시도
FoodItem temp = new FoodItem();
temp.setUid(Long.valueOf(1));
temp.setTitle("dd");
temp.setDetail("ddd");
for(int i=0;i<3;i++){
mdata.add(temp);}
//DB id값을 이용한 접근 쿼리
Cursor cursor = mdb.rawQuery("select * from " + mDbHelper_calendar.TABLE_NAME + " where " + mDbHelper_calendar.C_ID + "=" + mid, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
mtv_year.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.YEAR))+"년 ");
mtv_month.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.MONTH))+"월 ");
mtv_day.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DATE))+"일");
mtv_breakfast.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST)));
if(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST_KCAL))!=null){
mtv_breakfast_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST_KCAL))+" kcal");}
else{mtv_breakfast_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST_KCAL)));}
mtv_lunch.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH)));
if(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH_KCAL))!=null){
mtv_lunch_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH_KCAL))+" kcal");}
else{mtv_lunch_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH_KCAL)));}
mtv_dinner.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER)));
if(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER_KCAL))!=null){
mtv_dinner_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER_KCAL))+" kcal");}
else{ mtv_dinner_kcal.setText(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER_KCAL)));}
//이거 물어보기
FoodItem item = new FoodItem();
FoodItem item2 = new FoodItem();
FoodItem item3 = new FoodItem();
//수정 데이터 Arraylist에 담기
item.setTitle(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER)));
item.setDetail(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.DINNER_KCAL)));
mdata.set(2,item);
item2.setTitle(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST)));
item2.setDetail(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.BREAKFAST_KCAL)));
mdata.set(0,item2);
item3.setTitle(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH)));
item3.setDetail(cursor.getString(cursor.getColumnIndex(mDbHelper_calendar.LUNCH_KCAL)));
mdata.set(1,item3);
}
cursor.close();
mdb.close();
}
//수정데이터 arraylist 인텐트 받아오기
if((ArrayList<FoodItem>) modify.getSerializableExtra("list")!=null){
mdata = (ArrayList<FoodItem>) modify.getSerializableExtra("list");}
//수정된 값으로 setText
mtv_breakfast.setText(mdata.get(0).getTitle());
if (mdata.get(0).getDetail() != null) {
mtv_breakfast_kcal.setText(mdata.get(0).getDetail() + " kcal");
} else {
mtv_breakfast_kcal.setText(mdata.get(0).getDetail());
}
mtv_lunch.setText(mdata.get(1).getTitle());
if (mdata.get(1).getDetail() != null) {
mtv_lunch_kcal.setText(mdata.get(1).getDetail() + " kcal");
} else {
mtv_lunch_kcal.setText(mdata.get(1).getDetail());
}
mtv_dinner.setText(mdata.get(2).getTitle());
if (mdata.get(2).getDetail() != null) {
mtv_dinner_kcal.setText(mdata.get(2).getDetail() + " kcal");
} else {
mtv_dinner_kcal.setText(mdata.get(2).getDetail());
}
//동일한 Adapter를 사용하는 대신 식별자로 string값 사용
RecyclerViewAdapter.fromwhere = "searchmodify";
//수정된 데이터 식별
mwhen = fromAdapter.getStringExtra("when");
if(mwhen !=null) {
if (mwhen.equals("breakfast")) {
mtv_breakfast.setText(fromAdapter.getStringExtra("food_name"));
mtv_breakfast_kcal.setText(fromAdapter.getStringExtra("food_kcal")+" kcal");
} else if (mwhen.equals("lunch")) {
mtv_lunch.setText(fromAdapter.getStringExtra("food_name"));
mtv_lunch_kcal.setText(fromAdapter.getStringExtra("food_kcal")+" kcal");
} else if (mwhen.equals("dinner")) {
mtv_dinner.setText(fromAdapter.getStringExtra("food_name"));
mtv_dinner_kcal.setText(fromAdapter.getStringExtra("food_kcal")+" kcal");
}
}
//클릭리스너
mbtn_breakfast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mwhen = "breakfast";
//언제, 데이터값의 위치, 수정된 작은 데이터 arraylist 넘겨주기 점심, 저녁 클릭리스너 마찬가지
Intent intent = new Intent(SearchModifyActivity.this, FoodActicity.class);
intent.putExtra("when", mwhen);
intent.putExtra("id", mid);
intent.putExtra("list", mdata);
finish();
startActivity(intent);
}
});
mbtn_lunch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mwhen = "lunch";
Intent intent = new Intent(SearchModifyActivity.this, FoodActicity.class);
intent.putExtra("when", mwhen);
intent.putExtra("id", mid);
intent.putExtra("list", mdata);
finish();
startActivity(intent);
}
});
mbtn_dinner.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mwhen = "dinner";
Intent intent = new Intent(SearchModifyActivity.this, FoodActicity.class);
intent.putExtra("when", mwhen);
intent.putExtra("id", mid);
intent.putExtra("list", mdata);
finish();
startActivity(intent);
}
});
//완료 버튼 클릭시 DB에 저장
mbtn_complete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mdb =mDbHelper_calendar.getWritableDatabase();
ContentValues contentValues = new ContentValues();
//content value를 이용해 한번에 삽입
contentValues.put(mDbHelper_calendar.BREAKFAST, mdata.get(0).getTitle());
contentValues.put(mDbHelper_calendar.BREAKFAST_KCAL, mdata.get(0).getDetail());
contentValues.put(mDbHelper_calendar.LUNCH, mdata.get(1).getTitle());
contentValues.put(mDbHelper_calendar.LUNCH_KCAL, mdata.get(1).getDetail());
contentValues.put(mDbHelper_calendar.DINNER, mdata.get(2).getTitle());
contentValues.put(mDbHelper_calendar.DINNER_KCAL, mdata.get(2).getDetail());
//삽입 쿼리
mdb.update(mDbHelper_calendar.TABLE_NAME,contentValues,mDbHelper_calendar.C_ID+"="+ mid,null);
Intent openMainScreen = new Intent(SearchModifyActivity.this, SearchActivity.class);
mdb.close();
finish();
startActivity(openMainScreen);
}
});
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_Navigation_View);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_menu1: {
Intent goto_insert = new Intent(SearchModifyActivity.this, MainActivity.class);
startActivity(goto_insert);
break;
}
case R.id.navigation_menu2: {
Intent goto_search = new Intent(SearchModifyActivity.this, InsertActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu3: {
Intent goto_search = new Intent(SearchModifyActivity.this, SearchActivity.class);
startActivity(goto_search);
break;
}
case R.id.navigation_menu4: {
Intent goto_foodlist = new Intent(SearchModifyActivity.this, FoodActicity.class);
startActivity(goto_foodlist);
break;
}
}
return true;
}
});
}
//뒤로가기 버튼
@Override
public void onBackPressed(){
Intent intent = new Intent(SearchModifyActivity.this, SearchActivity.class);
startActivity(intent);
}
}
activity_search_modity.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="식단 기록 수정"
android:textColor="#000000"
android:fontFamily="@font/hoonddukbokki"
android:padding="10dp"
android:textSize="30sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="30dp">
<TextView
android:id="@+id/search_modify_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:id="@+id/search_modify_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:id="@+id/search_modify_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textColor="#000000"
android:textSize="30sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text="아침 "/>
<TextView
android:id="@+id/search_modify_breakfast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text=" "/>
<TextView
android:id="@+id/search_modify_breakfast_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text="점심 "/>
<TextView
android:id="@+id/search_modify_lunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text=" "/>
<TextView
android:id="@+id/search_modify_lunch_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text="저녁 "/>
<TextView
android:id="@+id/search_modify_dinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"
android:text=" "/>
<TextView
android:id="@+id/search_modify_dinner_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hoonwhitecatr"
android:textSize="30sp"
android:textColor="#000000"/>
</LinearLayout>
<Button
android:id="@+id/search_modify_lunch_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="점심식단 수정"
android:textSize="17sp"
android:background="@drawable/button"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:layout_margin="20dp"/>
<Button
android:id="@+id/search_modify_dinner_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="저녁식단 수정"
android:textSize="17sp"
android:background="@drawable/button"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:layout_margin="20dp"/>
<Button
android:id="@+id/search_modify_complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="변경하기"
android:textSize="17sp"
android:background="@drawable/button"
android:textColor="#000000"
android:fontFamily="@font/sangsangflowerroad"
android:layout_gravity="center"/>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_Navigation_View"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="bottom"
android:background="@color/cardview_dark_background"
app:menu="@menu/menu_bottom"
android:fitsSystemWindows="true"
app:labelVisibilityMode="unlabeled"
app:itemBackground="@color/cardview_dark_background"
app:itemIconTint="@drawable/item_color"
app:itemTextColor="@drawable/item_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
기타 디자인을위한 리소스 및 메뉴 xml파일은 올리지 않았다.
많은 것을 배워 뿌듯하다.