I have stuck with this issue more then 3 days. I have used one RecyclerView and on recyclerview's each item have on AutoCompleteTextView. When try to search on autocompletetextview drop down not display. Please do some help that how or where I need to update my code to use atutocomplettextview in every recyclerview items.
I have tried below are the cases:
- To show popup manually
autoCompleteTextView.showDropDown() - notify adapter when user is typing in autocompletetextview
- Every time reset the new adapter once use type on autocompletetextview
- I have tried all the option's of
android:windowSoftInputMode=""in AndroidMenifest - Checked more then 20+ questions on StackOver
- I have tried to set ArrayAdapter from
onBindViewHolder()method also
Below are the my code:
This is activity xml file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com..job..i.viewModel.job.JobViewModel" />
<import type="android.view.View" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/screenBG"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvSupervisor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:itemCount="1"
tools:listitem="@layout/job_filter_adapter" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
This is adapter class
public class JobFilterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public final String tag = JobFilterAdapter.class.getSimpleName();
private final Activity _activity;
private final LayoutInflater inflater;
private final List<StaffInfo> _staffList;
private final List<String> jobList;
public JobFilterAdapter(Activity activity, List<StaffInfo> staffList,
List<String> list) {
jobStaffAdapter = this;
_activity = activity;
inflater = _activity.getLayoutInflater();
_staffList = staffList;
jobList = list;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new AdapterHolder(DataBindingUtil.inflate(inflater, R.layout.row_job, parent, false),
new JObWatcher());
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
AdapterHolder adapterHolder = (AdapterHolder) holder;
StaffInfo model = _staffList.get(holder.getAdapterPosition());
adapterHolder.binding.autoCompleteTxtJob.setText(model.getStaffNo(), false);
adapterHolder.binding.txtStaffName.setText(model.getStaffName());
adapterHolder.jobWatcher.updateState(position, adapterHolder);
}
@Override
public int getItemCount() {
return _staffList.size();
}
class AdapterHolder extends RecyclerView.ViewHolder {
private final RowJobBinding binding;
JObWatcher jobWatcher;
ArrayAdapter jobArrayAdapter;
public AdapterHolder(@NonNull RowJobBinding _binding, JObWatcher _jobWatcher) {
super(_binding.getRoot());
binding = _binding;
jobWatcher = _jobWatcher;
jobArrayAdapter = new ArrayAdapter(_activity, R.layout.row_job_item,jobList);
binding.autoCompleteTxtJob.setThreshold(1);
}
}
public class JObWatcher {
int position;
AdapterHolder holder;
private void updateState(int pos, AdapterHolder viewHolder) {
position = pos;
holder = viewHolder;
manageAutoText();
}
private void manageAutoText() {
holder.binding.autoCompleteTxtJob.setOnFocusChangeListener((view, b) -> {
if (b) {
holder.binding.autoCompleteTxtJob.setAdapter(holder.jobArrayAdapter);
} else {
holder.binding.autoCompleteTxtJob.setAdapter(null);
}
});
}
}
}
This is adapter's item xml file
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:padding="@dimen/_5sdp">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatTextView
style="@style/txtJobDetailRowLeft"
android:text="@string/lbl_job" />
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/autoCompleteTxtJob"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="@drawable/bg_et_first"
android:gravity="center_vertical"
android:inputType="text"
android:paddingLeft="@dimen/_5sdp"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="@dimen/_9sdp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp"
android:layout_marginTop="@dimen/_5sdp"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatTextView
style="@style/txtJobDetailRowLeft"
android:text="@string/lbl_staff_name" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txtStaffName"
style="@style/txtJobDetailRowRight" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>