Reputation:
I am trying to make a DialogFragment that dynamically adds EditTexts to a RecyclerView as the user enters text in the fields. I am having trouble with something that should be quite easy.
I have the two initial EditText boxes I want, one has focus, one cannot gain focus yet. However, the keyboard never shows up. I can tap on the EditText to paste text, but nothing I do can get the keyboard to show up.
I am using a custom ArrayViewAdapter which extends RecyclerView.Adapter to place the EditText field in it's own Linear Layout.
Here is relevant code:
layout_linear.xml --> layout file for RecyclerView items
<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()
the xml file for the dialog:
<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>
Why won't the keyboard show up?
Upvotes: 0
Views: 175
Reputation: 1
Recyclerview seems to take focus away from the editText. This could work for you.
recyclerView.descendantFocusability = FOCUS_AFTER_DESCENDANTS
Upvotes: 0