【发布时间】:2021-03-26 15:51:59
【问题描述】:
当然是一个简单的问题,但我已经尝试了几个小时,但我似乎无法解决问题!
我有一个 DialogFragment,其中包含一个
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/interval_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeWidth="0dp">
<AutoCompleteTextView
android:id="@+id/time_interval_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
这是在这个 AutoCompleteView 上设置的监听器
binding.untilInput.onItemClickListener =
AdapterView.OnItemClickListener { parent, view, position, id ->
when (position) {
0 -> {
binding.numberLayout.visibility = View.GONE
}
1 -> {
binding.numberLayout.visibility = View.GONE
}
2 -> {
binding.numberLayout.visibility = View.VISIBLE
}
}
}
虽然数字布局只是像这样的线性布局
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="16dp">
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="For number of events"
android:textColor="?android:textColorSecondary" />
</androidx.appcompat.widget.LinearLayoutCompat>
起初监听器没有被调用所以我这样设置它而不是直接调用函数 setOnItemClickListener (不知道为什么不起作用),现在正在调用监听器,我什至放了一个断点并调试了它及其设置可见性,但它没有任何效果,也不会导致任何错误,所以我似乎无法在这里找到问题
【问题讨论】:
-
任何带有绑定的动作都不会在监听器内部起作用,即使我指定了另一个要调用的函数,它也不能用于绑定,但绑定不是问题!它工作正常
标签: android android-viewbinding