Я создал макет ограничения и вызываю фрагмент диалога из фрагмента. Но когда я нажимаю на кнопку, все, что она делает, это затухает на экране, но я не вижу ни одного диалога или макета.
Вот мой код фрагмента диалога:
package com.example.atry.MakeComplaint
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import com.example.atry.R
class PopupDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(activity)
return builder.create()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.existing_complaint_popup, container, false)
val yes = view.findViewById(R.id.YES) as Button
val no = view.findViewById(R.id.NO) as Button
// set onclicklistener
yes.setOnClickListener(View.OnClickListener {
// I want the dialog to close at this point
dismiss()
backFragment()
})
// set onclicklistener
no.setOnClickListener(View.OnClickListener {
// I want the dialog to close at this point
dismiss()
descriptionFragment()
})
return view
}
private fun backFragment() {
val manager = (context as AppCompatActivity).supportFragmentManager
manager.popBackStackImmediate()
}
private fun descriptionFragment() {
val dFragment= Category_Description()
val lFragment = LocationFragment()
val manager = (context as AppCompatActivity).supportFragmentManager
val transaction = manager.beginTransaction()
transaction.replace(
R.id.location_screen,
dFragment
) // give your fragment container id in first parameter
transaction.show(dFragment)
transaction.hide(lFragment)
transaction.isAddToBackStackAllowed
transaction.addToBackStack(lFragment.fragmentManager.toString()) // if written, this transaction will be added to backstack
transaction.commit()
}
}
Вот код внутри фрагмента, из которого я вызываю диалог:
//opening up the checkExisting popup
private fun existPopup(){
val fm = activity!!.supportFragmentManager
val dialog = PopupDialog() // creating new object
dialog.show(fm, "dialog")
}
А вот мой макет:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/textViewComplaint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/complainDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/textViewComplaint"
>
<TextView
android:id="@+id/headingComplain"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:layout_weight="6"
android:fontFamily="@font/pathway_gothic_one"
android:gravity="center"
android:padding="10dp"
android:text="Is this the complaint you're looking for?"
android:textColor="@color/white"
android:textSize="30sp"
/>
</LinearLayout>
<RelativeLayout
android:id="@+id/fazool"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:background="@color/grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/textViewComplaint"
android:background="@drawable/bottom_nav_border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewComplaint"
app:layout_constraintBottom_toBottomOf="parent"
>
<ScrollView
android:layout_height="wrap_content"
android:layout_width = "match_parent">
<include layout="@layout/existing_complaint_popup_inner"/>
</ScrollView>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>