如何在每个recyclerView项目中设置AutocompleteTextview及其适配器?

时间:2019-08-07 10:23:56

标签: android android-recyclerview sectionedrecyclerviewadapter

我想为每个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();
    }


}

0 个答案:

没有答案