android - Edittext 移动到 Recyclerview 的项目旁边
问题描述
我创建了一个回收器视图,其中一个是文本视图,另一个是编辑文本,其中数据是在运行时添加的,所以我想在单击键盘下一个按钮时这样做,然后它会移动到下一个编辑文本项问题是当我这样做时移动到文本视图而不是编辑文本等等......如下图所示。我该怎么做才能满足我的要求?我尝试了 sof 的所有答案,但失败了。
这是我的适配器代码,其中显示了该项目。
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
StudentMarks subject = subjectList.get(position);
holder.subjectName.setText(subject.getStudentsName());
holder.subjectId.setText(Collections.singletonList(subject.getStudentsId()).toString());
holder.subjectMarks.setText(subject.getStudentMarks());
if (!idStudent.contains(subject.getStudentsId())) {
idStudent.add(subject.getStudentsId());}
holder.subjectMarks.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
subjectList.get(position).setStudentMarks(holder.subjectMarks.getText().toString());
try {
String st_id = subjectList.get(position).getStudentsId();
for (int i = 0; i < id.size(); i++) {
if (id.get(i).equals(st_id)) {
id.remove(subjectList.get(position).getStudentsId());
value.remove(i);
}}
id.add(subjectList.get(position).getStudentsId());
value.add(holder.subjectMarks.getText().toString().trim());
} catch (Exception e) {
e.printStackTrace();
}
if (idStudent.toArray().length != id.toArray().length) {
listListener.onArrayListListener(id, value, position, "Please Enter Student Marks First");
} else {
listListener.onArrayListListener(id, value, position, "Student Marks Submitted");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.setIsRecyclable(false);
}
这是xml代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/add_student_category"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/_180sdp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:layout_marginBottom="@dimen/_8sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/add_marks_category"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/add_student_List"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:hint="@string/student_name"
android:inputType="none"
android:textColor="@color/greenish_shade"
android:textSize="@dimen/_12sdp"
tools:ignore="Deprecated,LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/add_marks_category"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/_80sdp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/add_student_category"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/add_student_category"
app:layout_constraintTop_toTopOf="@id/add_student_category">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/add_exam_marks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/obtain_marks"
android:inputType="number"
android:imeOptions="actionNext"
android:focusable="true"
android:focusableInTouchMode="true"
android:textAlignment="center"
android:textColor="@color/greenish_shade"
android:textColorHint="@color/greenish_shade"
android:textSize="@dimen/_12sdp"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0.5dp"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginEnd="@dimen/_8sdp"
android:background="@color/light_black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_student_category" />
<TextView
android:id="@+id/student_idss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
您可以添加android:maxLines="1" & android:inputType="text"
到您的 EditText。它肯定会奏效。
推荐阅读
- docker - 如何正确使用具有预计卷和 configMaps 的子目录
- python - 在请求中发现 Scrapy 和无效 cookie
- reactjs - React Native:用于显示模态的模态或反应导航
- c++ - 与main相比,如何使内部函数的数组大小输出相同?
- c++ - 在 Googletest 中实例化 Qt 应用程序和小部件导致 __acrt_first_block == 标头断言失败
- reactjs - 如何仅加载每个组件所需的 CSS(React js)
- c++ - 如何在不配置新工具链的情况下告诉 Bazel 使用哪个编译器
- javascript - 单击一键登录后,如何删除第二个身份验证屏幕?
- javascript - 在 useEffect 上设置参数并在 React Navigation 5 中的 createStackNav 上获取参数
- angular - 如何从角材料日期选择器中删除填充