-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
충남대 Android_정기주 2주차 과제 Step1 #31
base: ddangcong80
Are you sure you want to change the base?
충남대 Android_정기주 2주차 과제 Step1 #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다!
fun insertPlaceDummyData(context: Context, name: String, address: String, category: String) { | ||
val dbHelper = PlaceDBHelper(context) | ||
val db: SQLiteDatabase = dbHelper.writableDatabase | ||
val values = ContentValues() | ||
for (i: Int in 1..15) { | ||
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_NAME, name + i) | ||
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_ADDRESS, address + i) | ||
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_CATEGORY, category) | ||
db.insert(PlaceContract.PlaceEntry.TABLE_NAME, null, values) | ||
} | ||
db.close() | ||
} | ||
|
||
fun getAllPlaces(context: Context): List<String> { | ||
val dbHelper = PlaceDBHelper(context) | ||
val db: SQLiteDatabase = dbHelper.readableDatabase | ||
val cursor: Cursor = db.query( | ||
PlaceContract.PlaceEntry.TABLE_NAME, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null | ||
) | ||
|
||
val places = mutableListOf<String>() | ||
while (cursor.moveToNext()) { | ||
val name = | ||
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_NAME)) | ||
val address = | ||
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_ADDRESS)) | ||
val category = | ||
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_CATEGORY)) | ||
places.add("Name: $name, Address: $address, Category: $category") | ||
} | ||
cursor.close() | ||
db.close() | ||
|
||
for (place in places) { | ||
Log.d("ddangcong80", place) | ||
} | ||
|
||
return places | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 함수들은 Repository class로 빼서 들고 있으면 좋을 것 같습니다.
private var _searchText = MutableLiveData<String>() | ||
val searchText: LiveData<String> | ||
get() = _searchText | ||
|
||
fun clearSearchText() { | ||
_searchText.value = "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
searchText는 LiveData일 필요가 없을 것 같습니다.
데이터 변경이 일어나면 viewModel에 TextWatcher 를 통해서 바로바로 검색이 가능 할 것 같거든요
대신 list를 이후 step에서 livedata로 사용해보시길 바랍니다.
import campus.tech.kakao.map.model.PlaceContract | ||
import campus.tech.kakao.map.model.PlaceDBHelper | ||
|
||
class SearchViewModel : ViewModel() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
완벽하게 mvvm 아키텍쳐를 사용하기 위해서는
databinding을 꼭 사용해주어야 하는데요
https://hanyeop.tistory.com/377
요 블로그가 조금 도움이 될 것 같습니다.
다만 이번 학습의 범위를 넘어간다면 이 정도로도 괜찮을 듯 싶습니다.
} | ||
|
||
fun getAllPlaces(context: Context): List<String> { | ||
val dbHelper = PlaceDBHelper(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor cursor = null;
try{
cursor = database.rawQuery(strSQL, null);
if (cursor != null) {
// do action
}
} catch(Exception e) {
// exception
} finally {
if(cursor != null) cursor.close();
}
이런 형태의 예외처리가 들어가도 좋을 것 같습니다
과제 수행 시 어려웠던 점
중점적으로 리뷰해주셨으면 하는 부분