即使触摸,EditText也不会显示键盘

时间:2018-01-20 23:11:39

标签: android

我正在尝试创建一个DialogFragment,当用户在字段中输入文本时,会动态地将EditTexts添加到RecyclerView。我遇到的问题应该很容易。

我有两个我想要的初始EditText框,一个有焦点,一个无法获得焦点。但是,键盘永远不会出现。我可以点击EditText来粘贴文本,但我所做的一切都不能让键盘显示出来。

我正在使用一个自定义的ArrayViewAdapter,它扩展了RecyclerView.Adapter,将EditText字段放在它自己的线性布局中。

以下是相关代码:

layout_linear.xml - > RecyclerView项目的布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/ll"
    android:orientation="vertical"
    android:layout_weight="1">
</LinearLayout>

ArrayViewAdapter:

class ArrayViewAdapter<E>(val data: ArrayList<E>, c: Context) :
    RecyclerView.Adapter<ArrayViewAdapter.ViewHolder>() where E : View {
...
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
    val view = LayoutInflater.from(parent?.context)
            .inflate(R.layout.layout_linear, parent, false)
    return ViewHolder(view)
}
...
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    // The ID of the TableLayout
    val ll = itemView.findViewById<LinearLayout>(R.id.ll)

    fun bind(v : View) {
        ll.addView(v)
        ll.clearFocus()
    }
}

ListEntryDialog:

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val view = activity.layoutInflater.inflate(R.layout.fragment_list_entry_dialog, null)
...
val ed1 = EditText(activity)
    //ed1.addTextChangedListener(dw)
    ed1.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT)
    ed1.requestFocus()
val ed2 = EditText(activity)

    //ed2.addTextChangedListener(dw)
    ed2.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT)
    ed2.isFocusableInTouchMode = false
    ed2.isFocusable = false

    fields.add(ed1)
    fields.add(ed2)

    adapter = ArrayViewAdapter(fields, activity)
    rv.adapter = adapter
...
val builder = AlertDialog.Builder()
return builder.create()

对话框的xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:name="com.github.jlcarveth.grocer.layout.fragment.ListEntryDialog"
tools:context="com.github.jlcarveth.grocer.layout.fragment.ListEntryDialog">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/led_title"
        android:text="TITLE"/>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/led_rv"
        app:layoutManager="LinearLayoutManager">

    </android.support.v7.widget.RecyclerView>
</LinearLayout>

键盘为什么不显示?

0 个答案:

没有答案