Android Kotlin不工作时RecyclerView中的EditText

Android Kotlin不工作时RecyclerView中的EditText,android,kotlin,android-recyclerview,android-edittext,Android,Kotlin,Android Recyclerview,Android Edittext,我是新的应用程序开发人员,我对recyclerview项目中的EditText有问题 当用户单击编辑文本时,不会显示任何内容。我尝试在EditText上使用itemClickListener,click确实有效,但文本的Edition无效 这是我的密码: 活动: class MyIngredientListActivity : AppCompatActivity() { val ingerdientOfListArray = database.getAllIngredientOfList()

我是新的应用程序开发人员,我对recyclerview项目中的EditText有问题

当用户单击编辑文本时,不会显示任何内容。我尝试在EditText上使用itemClickListener,click确实有效,但文本的Edition无效

这是我的密码:

活动:

class MyIngredientListActivity : AppCompatActivity() {

val ingerdientOfListArray = database.getAllIngredientOfList()
val adapter = IngredientOfListAdapter(ingerdientOfListArray)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.ingredient_list_recyclerview)

    findViewById<Button>
    (R.id.ingredient_list_activity_search_button).setOnClickListener {

        val intent = Intent(this, IngredientSearchableActivity::class.java)
        startActivity(intent)
    }

    val recyclerView = findViewById<RecyclerView> 
    (R.id.ingredientoflist_recyclerview)
    recyclerView.layoutManager = LinearLayoutManager(this)
    recyclerView.adapter = adapter

}


override fun onResume() {
    super.onResume()

    adapter.updateIngredientList()
}
类MyIngredientListActivity:AppCompatActivity(){
val ingerdientOfListArray=database.getAllIngredientOfList()
val适配器=IngRedientFlistaAdapter(ingerdientOfListArray)
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.Component\u list\u recyclerview)
findviewbyd
(R.id.component\u list\u activity\u search\u按钮){
val intent=intent(这是IngreditSearchableActivity::class.java)
星触觉(意图)
}
val recyclerView=findviewbyd
(R.id.ingredientoflist_recyclerview)
recyclerView.layoutManager=LinearLayoutManager(此)
recyclerView.adapter=适配器
}
重写onResume(){
super.onResume()
adapter.updateIngredientList()
}
适配器:

class IngredientOfListAdapter(val ingredientOfListDisplay: 
ArrayList<IngredientOfList>
): RecyclerView.Adapter<IngredientOfListAdapter.ViewHolder>() {



class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {


    val cardView = itemView.findViewById<CardView> 
(R.id.ingredientoflist_cardview_name)
    val name = itemView.findViewById<TextView>(R.id.ingredientoflist_name)
    val checkbox = itemView.findViewById<CheckBox> 
(R.id.ingredientoflist_checkbox)
    val editText = itemView.findViewById<EditText> 
(R.id.ingredientoflist_quantity)
    val unitmeasure = itemView.findViewById<TextView> 
(R.id.ingredientoflist_unitmeasure)

    }



override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val viewItem = inflater.inflate(R.layout.ingredient_list_item, parent, false)

    return ViewHolder(viewItem)
}



override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val ingredientOfList = ingredientOfListDisplay[position]        

    val ingredientFromId = database.readIngredientById(ingredientOfList).first()
    val unitMeasureId = database.readUnitMeasureById(ingredientFromId).first()     


    holder.cardView?.tag = position
    holder.name.text = ingredientFromId.name
    holder.unitmeasure.text = unitMeasureId.symbol

    holder.editText?.tag = position
    holder.editText.setText(0)

}

override fun getItemCount(): Int {
    return ingredientOfListDisplay.size
}


fun updateIngredientList(ingredientOfListArray: ArrayList<IngredientOfList> = database.getAllIngredientOfList()) {

    ingredientOfListDisplay.clear()
    ingredientOfListDisplay.addAll(ingredientOfListArray)
    notifyDataSetChanged()
}

}
class IngRedientFlistAdapter(val IngRedientFlistDisplay:
ArrayList
):RecyclerView.Adapter(){
类ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){
val cardView=itemView.findViewById
(R.id.INGREDINTOFLIST\U cardview\U名称)
val name=itemView.findViewById(R.id.ingredientoflist_name)
val checkbox=itemView.findviewbyd
(R.id.ingredientoflist_复选框)
val editText=itemView.findViewById
(R.id.INGREDINTOFLIST\U数量)
val unitmeasure=itemView.findviewbyd
(R.id.ingredientoflist_unitmeasure)
}
override onCreateViewHolder(父级:ViewGroup,viewType:Int):ViewHolder{
val inflater=LayoutInflater.from(parent.context)
val viewItem=充气机。充气(R.layout.false)
返回ViewHolder(viewItem)
}
覆盖BindViewHolder(holder:ViewHolder,位置:Int){
val IngRedientFlist=IngRedientFlistDisplay[位置]
val ingredientFromId=database.readIngredientById(IngRedientFlist).first()
val unitMeasureId=database.readUnitMeasureById(ingredientFromId).first()
支架.cardView?.tag=位置
holder.name.text=ingredientFromId.name
holder.unitmeasure.text=unitMeasureId.symbol
holder.editText?.tag=位置
holder.editText.setText(0)
}
重写getItemCount():Int{
return ingredientOfListDisplay.size
}
fun updateIngredientList(IngRedientFlitStarray:ArrayList=database.GetAllingRedientFlist()){
ingredientOfListDisplay.clear()
IngRedientFlistDisplay.addAll(IngRedientFlistStarray)
notifyDataSetChanged()
}
}
你在这儿吗

这里是cardview

    android:id="@+id/ingredientoflist_cardview_name"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cardUseCompatPadding="true"
    android:focusable="false"
    android:clickable="false"
    android:foreground="?android:attr/selectableItemBackground">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#C3FFFFFF">

        <TextView
            android:id="@+id/ingredientoflist_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:textColor="#403E3E"
            android:textSize="17sp"
            android:textStyle="bold"
            tools:text="ingredient"/>

        <EditText
            android:id="@+id/ingredientoflist_quantity"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_alignParentBottom="true"
            android:layout_marginStart="250dp"
            android:layout_marginLeft="250dp"
            android:layout_marginBottom="8dp"
            android:clickable="true"
            android:focusable="true"
            android:inputType="number"
            android:imeOptions="actionDone"
            android:saveEnabled="true"
            android:hint="00"
            android:textColor="#403E3E"
            android:textSize="17sp"
            android:textStyle="bold"
            android:gravity="center_horizontal"
            android:background="@drawable/abc_vector_test" />

        <TextView
            android:id="@+id/ingredientoflist_unitmeasure"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:layout_marginStart="305dp"
            android:layout_marginLeft="305dp"
            android:hint="cl"
            android:textColor="#403E3E"
            android:textSize="17sp"
            android:textStyle="bold"/>

        <CheckBox
            android:id="@+id/ingredientoflist_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="350dp"
            android:layout_marginLeft="350dp"
            android:gravity="center_vertical"/>

    </RelativeLayout>

</CardView>
android:id=“@+id/ingredientoflist\u cardwiew\u name”
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
app:cardUseCompatding=“true”
android:focusable=“false”
android:clickable=“false”
android:前台=“?android:attr/selectableItemBackground”>
回收视图布局:

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/NoActionBar"
android:background="#000000">


<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_below="@+id/ingredient_search_activity_search_button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:paddingBottom="60dp"
    app:srcCompat="@drawable/baseline_no_food_white_48"
    app:tint="#40FFFFFF" />

<Button
    android:id="@+id/ingredient_search_activity_search_button"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@android:color/white"
    android:drawableStart="@android:drawable/ic_search_category_default"
    android:drawableLeft="@android:drawable/ic_search_category_default"
    android:gravity="start|center_vertical"
    android:text="@string/my_searchables_ingredients"
    android:textAlignment="textStart"
    android:focusable="false"
    android:clickable="true"/>


<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/ingredientoflist_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#C3FFFFFF"
    app:queryHint="your ingredients"
    android:layout_below="@id/ingredient_search_activity_search_button"
    android:clickable="false"
    android:focusable="false"/>

</RelativeLayout>

谢谢,祝你今天愉快!

我想

holder.editText.setOnClickListener(Object : View.OnClickListener {
    override fun OnClick(v: View?) {
        v.requestFocus()
    }
}

应该可以。我对Kotlin不是很在行,所以可能有语法错误。

请在
R.layout.component\u list\u item.xml中发布edittext代码
对不起,我现在就做对不起,回复这么晚!这是我犯的错误,因为在edittext和布局可聚焦和可单击属性之间创建冲突。我解决了它,声明布局可聚焦,可点击为false。