soonmyeong2

make search bar;

......@@ -37,7 +37,7 @@ dependencies {
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-database:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
......@@ -15,6 +15,14 @@
},
"oauth_client": [
{
"client_id": "1004426035643-ju8i4dbd1psjka5qqjsntos2kodrt2ca.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.vip",
"certificate_hash": "8ac95d8222d265210a8ef81c0f1fa04561152680"
}
},
{
"client_id": "1004426035643-0id5kb6rfoi38qi0ji2tvm7o8vvinvbe.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
......
......@@ -11,6 +11,7 @@
<activity android:name=".SignInActivity"></activity>
<activity android:name=".SignUpActivity" />
<activity android:name=".MainActivity"/>
<activity android:name=".SearchActivity"/>
<activity android:name=".SplashActivity" android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.example.vip
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
//import androidx.appcompat.widget.SearchView
import android.widget.SearchView
import android.widget.Toast
import androidx.core.app.ComponentActivity.ExtraData
import androidx.core.content.ContextCompat.getSystemService
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
import android.view.View
import android.widget.Button
import android.content.Intent
import android.util.Log
import com.google.firebase.database.*
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
data class MemoItem(
val Target : String = "",
val Policy : String = "",
val Content : String = "",
val Link : String = ""
)
var database = FirebaseDatabase.getInstance().reference
class SearchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.search)
val searchView: SearchView
searchView = findViewById(R.id.searchForm)
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
// 검색 버튼이 눌러졌을 때 이벤트 처리
database.orderByChild("Policy").startAt("$query").endAt("$query"+"\uf8ff").addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
Toast.makeText(this@SearchActivity, "실패부분 : $query", Toast.LENGTH_SHORT).show()
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
// 타겟 1개 if (dataSnapshot.exists()){
// val memo = dataSnapshot.getValue(MemoItem::class.java)
// if (memo != null){
// Toast.makeText(this@SearchActivity, memo!!.Policy, Toast.LENGTH_SHORT).show()
// }
//
// }
for(memoSnapshot in dataSnapshot.children){
val memo = memoSnapshot.getValue(MemoItem::class.java)
Toast.makeText(this@SearchActivity, memo!!.Policy, Toast.LENGTH_SHORT).show()
}
}
})
Toast.makeText(this@SearchActivity, "검색 처리됨 : $query", Toast.LENGTH_SHORT).show()
return true
}
override fun onQueryTextChange(newText: String): Boolean {
// 검색어가 변경되었을 때 이벤트 처리
return false
}
})
}
}
\ No newline at end of file
package com.example.vip
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
......@@ -108,7 +109,9 @@ class SignInActivity : AppCompatActivity() {
Snackbar.make(toolbar,"Menu pressed",Snackbar.LENGTH_SHORT).show()
}
R.id.menu_search->{ // 검색 버튼
Snackbar.make(toolbar,"Search menu pressed",Snackbar.LENGTH_SHORT).show()
val search_Intent = Intent(this, SearchActivity::class.java)
startActivity(search_Intent)
//Snackbar.make(toolbar,"Search menu pressed",Snackbar.LENGTH_SHORT).show()
}
}
return super.onOptionsItemSelected(item)
......
......@@ -10,7 +10,6 @@ class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SearchView
android:id="@+id/searchForm"
android:queryHint="복지 정책 입력"
app:showAsAction="always"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</SearchView>
</LinearLayout>
\ No newline at end of file