我想为每个RecyclerView
项分别具有一个RecyclerView
和一个AutocompletetextView
设置一个ImageButton
,并在主UI上单击一个按钮,该项目应添加后,用户可以在AutoCompleteTextView
中输入相关数据,并在输入时显示自动完成建议。
public class SensorListAdapter extends RecyclerView.Adapter<SensorListAdapter.SensorListViewHolder> {
List<CrateSensors> crateSensorsList;
List<String> TagStrings;
public SensorListAdapter(List<CrateSensors> crateSensorsList) {
this.crateSensorsList = crateSensorsList;
}
public class SensorListViewHolder extends RecyclerView.ViewHolder{
AutoCompleteTextView mBarcode ; ImageButton mBarcodeImageButton;
ArrayAdapter mTagArrayAdapter;
public SensorListViewHolder(View itemView) {
super(itemView);
mBarcode = itemView.findViewById(R.id.Sensor_List_Enterbarcode_AutoCompleteTextView);
mBarcodeImageButton = itemView.findViewById(R.id.Sensor_List_Enterbarcode_ImageButton);
mTagArrayAdapter = new ArrayAdapter<String>( itemView.getContext(), android.R.layout.simple_dropdown_item_1line,TagStrings);
mBarcode.setAdapter(mTagArrayAdapter);
mBarcode.setThreshold(1);
mBarcode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBarcode.showDropDown();
}
});
}
}
@NonNull
@Override
public SensorListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.sensor_item ,parent,false);
return new SensorListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull SensorListViewHolder holder, int position) {
CrateSensors crateSensors = crateSensorsList.get(position);
}
@Override
public int getItemCount() {
return crateSensorsList.size();
}
}