Bonjour,

J'ai un problème avec les addTextChangedListener d'un recyclerview : le addTextChangedListener est déclenché au premier scroll de l'écran, pourtant cela n'a aucun rapport...

Qu'est ce qui pourrait clocher ?

J'ai beaucoup cherché sans succès...

Merci par avance !

Code kotlin : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
open class CustomAdapter(private val data: DataClass, private val activity: MainActivity) :
        RecyclerView.Adapter<CustomAdapter.ViewHolder>() {
 
    init {
 
 
        setHasStableIds(true)
 
 
 
    }
 
    internal lateinit var list: List<String>
 
 
    override fun onCreateViewHolder(
            parent: ViewGroup,
            viewType: Int
    ): ViewHolder {
 
 
        val rowItem: View =
                LayoutInflater.from(parent.context).inflate(com.example.essai2.R.layout.list_item_view, parent, false)
 
        var myview= ViewHolder(rowItem)
 
      // myview.setOnClickListener()
      // myview.setOnClickListener2()
 
        return myview
 
 
    }
 
    override fun onBindViewHolder(
            holder: ViewHolder,
            position: Int
    ) {
 
        holder.editText.setText(data.list1[position])
        holder.editText2.setText(data.list2[position])
        holder.textview.setText(data.list3[position])
        holder.setOnClickListener()
        holder.setOnClickListener2()
 
 
    }
 
 
 
 
 
 
 
 
 
    override fun getItemId(position: Int): Long {
        return position.toLong()
    }
 
 
    override fun getItemCount(): Int {
        return data.list1.size
    }
 
   inner class ViewHolder(rowItem: View) : RecyclerView.ViewHolder(rowItem) {
 
        val textview : TextView = rowItem.findViewById(com.example.essai2.R.id.textview)
        val editText : EditText= rowItem.findViewById(com.example.essai2.R.id.editText)
        val editText2 : EditText= rowItem.findViewById(com.example.essai2.R.id.editText2)
 
 
        fun fonction3(position: Int)
        {
              if (position >=1 && position <=98) {
                  data.list3[position] = (0.5 * (data.list2[position - 1].toDouble() + data.list2[position + 1].toDouble())).toString()
                  //activity.Update()
              }
        }
 
 
 
 
 
        fun setOnClickListener() {
 
            editText.addTextChangedListener(object : TextWatcher {
                override fun afterTextChanged(p0: Editable?) {
                    data.list1[getAdapterPosition()]= editText.text.toString()
                    activity.fonction()
                }
 
                override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
 
                }
 
                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
 
 
                }
 
 
 
 
 
            })
 
 
 
        }
 
 
 
 
 
 
 
 
 
 
 
        fun setOnClickListener2() {
 
 
 
 
            editText2.addTextChangedListener(object : TextWatcher {
                override fun afterTextChanged(p0: Editable?) {
                    data.list2[getAdapterPosition()] = editText2.text.toString()
                    activity.fonction2()
                    fonction3(getAdapterPosition())
 
                }
 
                override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
 
                }
 
                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
 
 
                }
 
 
            })
 
        }
 
 
 
 
 
 
 
 
 
 
        init {
 
 
        }
    }
 
}