TimePicker из RecyclerView / Adapter просто тускнеет экран - PullRequest
0 голосов
/ 08 февраля 2019

Новичок в разработке для Android и не может понять, как заставить TimePicker всплывать при нажатии элемента / View в моем элементе RecyclerView.У меня есть фрагмент с RecyclerView, и я следовал https://developer.android.com/guide/topics/ui/controls/pickers,, но когда я щелкаю по элементу, экран просто немного тускнеет, и все.Средство выбора никогда не отображается.

Спасибо.

MainActivity.kt

class MainActivity : AppCompatActivity() {
    //...
    override fun onCreate(savedInstanceState: Bundle?) {
        //...
        navigation.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener)
        //...
    }

    private val onNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.navigation_people -> {
                findViewById<TextView>(R.id.title).text = "People"
                supportFragmentManager.transaction(allowStateLoss = true) {
                    replace(R.id.container, PeopleFragment.newInstance())
                }
                return@OnNavigationItemSelectedListener true
            }
            //...
        }
        false
    }
}

Adapter.kt

class Adapter: ListAdapter<Person, PeopleViewAdapter.ViewHolder>(PeopleDiffCallback()) {
//...
    class ViewHolder(val binding: FragmentPeopleDetailBinding) : RecyclerView.ViewHolder(binding.root),
        View.OnClickListener, CompoundButton.OnCheckedChangeListener, ChipGroup.OnCheckedChangeListener {
    //...
        override fun onClick(v: View?) {
            v?.let {
                when (v.id) {
                    //...
                    itemView.start.id -> TimePickerFragment.newInstance(1, 1)
                            .show((v.context as AppCompatActivity).supportFragmentManager, "Test")
                //...
                }
            }
        }
    }
    //..
}

TimePickerFragment.kt

class TimePickerFragment : DialogFragment(), TimePickerDialog.OnTimeSetListener {
    companion object {
        fun newInstance(hour: Int, minute: Int) = DialogFragment().apply {
            arguments = Bundle().apply {
                putInt("hour", hour)
                putInt("minute", minute)
            }
        }
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        super.onCreateDialog(savedInstanceState)

        var hour = 1
        var minute = 1

        arguments?.let {
            hour = it.getInt("hour")
            minute = it.getInt("minute")
        }

        return TimePickerDialog(activity, this, hour, minute, DateFormat.is24HourFormat(context))
    }

    override fun onTimeSet(view: TimePicker?, hourOfDay: Int, minute: Int) {
        Log.d(TAG, "Picked $hourOfDay for hour and $minute for minute.")
    }
}
...