작성
·
323
답변 4
0
확인이 늦어서 죄송합니다.
Context -> this 로 변경해보시겠어요?
잘 안되시면 전체 코드를 압축해서 uyalae@naver.com 로 전달주시면 살펴보겠습니다.
0
0
ImdaeListActivity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.mymemul.ListTextView.ImdaeListModel
import com.example.mymemul.R
import com.example.mymemul.Todo.ImdaeListRvAdapter
import com.example.mymemul.databinding.ActivityImdaeListBinding
import com.example.mymemul.util.FBAuth
import com.example.mymemul.util.FBRef
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.ktx.Firebase
class ImdaeListActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private val imdaeDataList = mutableListOf<ImdaeListModel>()
// private val ImdaeKeyList = mutableListOf<String>()
private val TAG = ImdaeListActivity::class.java.simpleName
private lateinit var binding: ActivityImdaeListBinding
private lateinit var imdaeListAdapter: ImdaeListRvAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_imdae_list)
binding = ActivityImdaeListBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
auth = Firebase.auth
binding.imdaeListBtn.setOnClickListener {
val intent = Intent(this, ImdaeSaActivity::class.java)
startActivity(intent)
}
imdaeListAdapter = ImdaeListRvAdapter(imdaeDataList)
binding.imdaeListView.adapter = imdaeListAdapter
binding.imdaeListView.setOnItemClickListener { parent, view, position, id ->
val intent = Intent(context, ImdaeSsbActivity::class.java)
startActivity(intent)
}
//임대 리스트
getImdaeListData()
}
private fun getImdaeListData() {
val postListener = object : ValueEventListener {
override fun onDataChange(datasnapshot: DataSnapshot) {
imdaeDataList.clear()
for (dataModel in datasnapshot.children) {
Log.d(TAG, dataModel.toString())
val item = dataModel.getValue(ImdaeListModel::class.java)
imdaeDataList.add(item!!)
// ImdaeKeyList.add(dataModel.key.toString())
}
imdaeListAdapter.notifyDataSetChanged()
}
override fun onCancelled(databaseError: DatabaseError) {
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
var uid = FBAuth.getUid()
FBRef.user
.child("Imdae")
.child(uid)
.addValueEventListener(postListener)
}
}
ImdaeSaActivity
class ImdaeSaActivity : AppCompatActivity() {
private val TAG = ImdaeSaActivity::class.java.simpleName
private lateinit var auth: FirebaseAuth
private var mEtAddress: EditText? = null
// private val data = arrayListOf<ImdaeTodo>()
private lateinit var binding: ActivityImdaeSaBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.activity_imdae_sa)
binding = DataBindingUtil.setContentView(this, R.layout.activity_imdae_sa)
auth = Firebase.auth
// auth = FirebaseAuth.getInstance()
// binding = ActivityImdaeListBinding.inflate(layoutInflater)
// val view = binding.root
// setContentView(view)
binding.imdaeBtn.setOnClickListener {
val uid = auth.currentUser?.uid.toString()
val mulgun = binding.mulgunall.text.toString()
val sename = binding.sename.text.toString()
val sephone = binding.sephoneno.text.toString()
val address = binding.etAddress.text.toString()
val address1 = binding.etAddress1.text.toString()
val bojung = binding.bojung.text.toString()
val worldse = binding.worldse.text.toString()
val kwanry1 = binding.kwanry1.text.toString()
val kwanry2 = binding.kwanry2.text.toString()
val mjbb = binding.myungjuk.text.toString()
val cgbb = binding.chunggo.text.toString()
val time = FBAuth.getTime()
Log.d(TAG, sename)
Log.d(TAG, sephone)
FBRef.user
.child("Imdae")
.child(uid)
.push()
.setValue(
ImdaeitemModel(mulgun,sename,sephone,address,address1,
bojung,worldse,kwanry1,kwanry2,mjbb,cgbb, time)
)
Toast.makeText(this,"임대자료 입력완료", Toast.LENGTH_LONG).show()
finish()
}
}
}
ImdaeListRvAdapter
class ImdaeListRvAdapter (val imdaeDataList : MutableList<ImdaeListModel>) : BaseAdapter() {
override fun getCount(): Int {
return imdaeDataList.size
}
override fun getItem(position: Int): Any {
return imdaeDataList[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var view = convertView
if (view == null) {
view = LayoutInflater.from(parent?.context).inflate(R.layout.activity_imdae_list_adapter,parent, false)
}
val mulgun = view?.findViewById<TextView>(R.id.mul)
val sename = view?.findViewById<TextView>(R.id.sename12)
mulgun!!.text = imdaeDataList[position].mulgun
sename!!.text = imdaeDataList[position].sename
return view!!
}
}
ImdaeListModel
class ImdaeListModel (
val mulgun: String = "",
val sename: String = "",
)
activity_imdae_list
<layout>
<androidx.constraintlayout.widget.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=".List.ImdaeListActivity">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFD968"
android:orientation="vertical">
<TextView
android:id="@+id/imdaetitle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#FFD968"
android:gravity="center_horizontal|center_vertical"
android:text="임 대"
android:textSize="20sp"
android:textColor="#704300"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:background="@drawable/mocer_call_mulback1"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="No"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="날짜"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="세입자"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="주 소"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="보증금"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="월세"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="관리비"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="권리금"
android:textSize="20dp" />
<LinearLayout
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="면적"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/imdaeListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp" />
</LinearLayout>
<ImageView
android:id="@+id/imdaeListBtn"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/pen"
android:elevation="20dp"
app:layout_constraintBottom_toBottomOf="@+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
activity_imdae_ssb
<layout>
<androidx.constraintlayout.widget.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=".List.ImdaeSsbActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
0
퇴근후에 살펴보겠습니당 ㅠㅠ