Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 回收视图片段onClick-won';不显示下一个片段_Kotlin_Android Recyclerview_Fragment - Fatal编程技术网

Kotlin 回收视图片段onClick-won';不显示下一个片段

Kotlin 回收视图片段onClick-won';不显示下一个片段,kotlin,android-recyclerview,fragment,Kotlin,Android Recyclerview,Fragment,我正在开发一个应用程序,recyclerView发出咔嗒声,让我知道onClickListener功能正常。它只是没有显示下一个片段。我真的需要帮助,如果我应该使用碎片管理器,如果是这样的话,我应该把它放在哪里 HomeFragment import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import andr

我正在开发一个应用程序,recyclerView发出咔嗒声,让我知道onClickListener功能正常。它只是没有显示下一个片段。我真的需要帮助,如果我应该使用碎片管理器,如果是这样的话,我应该把它放在哪里

HomeFragment


import android.os.Bundle

import android.view.LayoutInflater

import android.view.View

import android.view.ViewGroup

import androidx.fragment.app.Fragment

import androidx.lifecycle.ViewModelProviders

import androidx.recyclerview.widget.LinearLayoutManager

import androidx.recyclerview.widget.RecyclerView

import com.example.spirituality101.R

import com.example.spirituality101.R.drawable.*

import kotlinx.android.synthetic.main.fragment_home.*

class HomeFragment : Fragment(), ZodiacAdapter.MyItemClickListener {

    private lateinit var homeViewModel: HomeViewModel
    private lateinit var adapter: ZodiacAdapter
    private var listener: OnRecyclerInteractionListener? = null




    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        homeViewModel =
            ViewModelProviders.of(this).get(HomeViewModel::class.java)
        return inflater.inflate(R.layout.fragment_home, container, false)


    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val linearLayoutManager: RecyclerView.LayoutManager
        linearLayoutManager = LinearLayoutManager(view.context)
        zodiacRec.setHasFixedSize(true)
        zodiacRec.layoutManager = linearLayoutManager





        ArrayList<Zodiac>().apply {
            add(Zodiac("Aries", "Zodiac Date: March 21 - April 20, The Aries zodiac sign is the 1st sign of the zodiac. The Aries people are willful, feisty, self-centered, courageous, bold, foolhardy, independent and straightforward.",
                aries
            ))
            add(Zodiac("Taurus", "April 21 - May 21, The Taurus zodiac sign is the 2nd sign of the zodiac. The Taurus people are practical, creative, loyal, possessive, temperamental, sensually indulgent, down-to-earth, dependable, persistent and practical.",
                taurus
            ))
            add(Zodiac("Gemini", "May 22 - June 21, The Gemini zodiac sign is the 3rd sign of the zodiac. The Gemini people are curious, elusive, unpredictable, changeable, versatile, childlike, romantic, playful, friendly, talkative and have a keen intellect.",
                gemini
            ))
            add(Zodiac("Cancer", "June 22 - July 22, The Cancer zodiac sign is the 4th sign of the zodiac. The Cancer people are cautious, protective, nurturing, secretive, instinctive, needy, sensitive, funny, empathetic and deeply complex people.",
                cancer
            ))
            add(Zodiac("Leo", "July 23 - August 21, The Leo zodiac sign is the 5th sign of the zodiac. The Leos are distinctive, provocative, demanding, goal-oriented, flamboyant, self-made, warm, outgoing, sincere and loyal people.",
                leo
            ))
            add(Zodiac("Virgo", "August 22 - September 23, The Virgo zodiac sign is the 6th sign of the zodiac. The Virgos are discriminating, obsessive, realistic, analytical, reliable, self-contained, knowledgeable, predictable, obsessive, discriminating, street-smart, detailed and modest people.",
                virgo
            ))
            add(Zodiac("Libra", "September 24 - October 23, The Libra zodiac sign is the 7th sign of the zodiac. The Libra is the only zodiac sign that has an inanimate object, the scales, as its symbol. Librans are harmonious, civilized, intellectual, sophisticated, seductive, elegant, creative, witty, balanced, sociable and people who maintain their status quo.",
                libra
            ))
            add(Zodiac("Scorpio", "October 24 - November 22, The Scorpio zodiac sign is the 8th sign of the zodiac. The Scorpio people are intense, magnetic, erotic, challenging, secretive, powerful, broody, passionate, immovable and penetrating.",
                scorpio
            ))
            add(Zodiac("Sagittarius", "November 23 - December 22, The Sagittarius zodiac sign is the 9th sign of the zodiac. The Sagittarius are adventurous, hilarious, extrovert, romantics, spirited, unstoppable, generous, happy and open-minded.",
                saggitarius
            ))
            add(Zodiac("Capricorn", "December 23 - January 20, The Capricorn zodiac sign is the 10th sign of the zodiac. The Capricorn people are organized, respectful, devoted, classy, materialistic, serious, staid, ambitious and practical.",
                capricorn
            ))
            add(Zodiac("Aquarius", "January 21 - February 19, The Aquarius zodiac sign is the 11th sign of the zodiac. Aquarius people are original, idealistic, rebellious, independent, inventors, open minded and honest.",
                aquarius
            ))
            add(Zodiac("Pisces", "February 20 - March 20, The Pisces zodiac sign is the 12th sign of the zodiac. Pisceans are dreamy, erratic, creative, romantic, compassionate, elusive, imaginative, sensitive and kind people.",
                pisces
            ))

            adapter = ZodiacAdapter(this)
        }
        adapter.setMyItemClickListener(this)
        zodiacRec.adapter = adapter



    }

    interface OnRecyclerInteractionListener {
        fun onItemClicked(zodiac: Zodiac)




    }

    override fun onItemClickedFromAdapter(zodiac: Zodiac) {
        onItemClickedFromRecyclerViewFragment(zodiac)


    }

    private fun onItemClickedFromRecyclerViewFragment(zodiac: Zodiac) {
        listener?.onItemClicked(zodiac)
    }

}

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.spirituality101.R


// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Activities that contain this fragment must implement the
 * [ZodiacDetailFragment.OnFragmentInteractionListener] interface
 * to handle interaction events.
 * Use the [ZodiacDetailFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class ZodiacDetailFragment : Fragment() {
    private var listener: OnFragmentInteractionListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {

        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_zodiac_detail, container, false)

    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        if (context is OnFragmentInteractionListener) {
            listener = context
        } else {
            throw RuntimeException("$context must implement OnFragmentInteractionListener")
        }
    }

    override fun onDetach() {
        super.onDetach()
        listener = null
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     *
     *
     * See the Android Training lesson [Communicating with Other Fragments]
     * (http://developer.android.com/training/basics/fragments/communicating.html)
     * for more information.
     */
    interface OnFragmentInteractionListener

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment ZodiacDetail.
         */

        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            ZodiacDetailFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }


}
最后一个是我希望在单击回收项目后显示的。我没有把任何东西加入到细节片段中,因为点钟没有显示页面。我尝试使用FragmentManager,但在应用程序不停关闭的情况下,我想不出应该把它放在哪里


import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.spirituality101.R


// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Activities that contain this fragment must implement the
 * [ZodiacDetailFragment.OnFragmentInteractionListener] interface
 * to handle interaction events.
 * Use the [ZodiacDetailFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class ZodiacDetailFragment : Fragment() {
    private var listener: OnFragmentInteractionListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {

        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_zodiac_detail, container, false)

    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        if (context is OnFragmentInteractionListener) {
            listener = context
        } else {
            throw RuntimeException("$context must implement OnFragmentInteractionListener")
        }
    }

    override fun onDetach() {
        super.onDetach()
        listener = null
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     *
     *
     * See the Android Training lesson [Communicating with Other Fragments]
     * (http://developer.android.com/training/basics/fragments/communicating.html)
     * for more information.
     */
    interface OnFragmentInteractionListener

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment ZodiacDetail.
         */

        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            ZodiacDetailFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }


}