Recyclerview 根据点击的项目获取项目价值

Recycle view get item value base on item clicked

我刚刚创建了一个带有回收视图的对话框。当我单击该项目时,它应该根据我单击的内容设置编辑文本。但它没有,它在回收视图中显示了第一个值。有人可以帮助我根据我点击的内容获得价值基础。我只是创建一个带有回收视图的对话框。当我单击该项目时,它应该根据我单击的内容设置编辑文本。但它没有,它在回收视图中显示了第一个值。有人可以帮我根据我点击的内容获得价值吗

@SuppressLint("ResourceType")
@OnClick(R.id.button_choose)
void chooseLOV() {

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.lov_kodepos, null);
    dialogBuilder.setView(dialogView);

    final RecyclerView recyclerView = (RecyclerView) dialogView.findViewById(R.id.rv_lov_kodepos);
    final EditText search  = (EditText) dialogView.findViewById(R.id.editText_lov_search);
    search.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) {
            ArrayList<KodePos> kodePos = new ArrayList<>();
            if (tempData!=null){
                for (KodePos kodePosSatu: data ){
                    String dat = s.toString().toLowerCase();
                    if (kodePosSatu.getPosCamat().toLowerCase().contains(dat)) {
                        kodePos.add(kodePosSatu);
                    }
                }
                tempData = kodePos;
                recyclerView.setAdapter(new KodePosAdapter(tempData));
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });


    API.getKodePos().enqueue(new Callback<ArrayList<KodePos>>() {
        @Override
        public void onResponse(Call<ArrayList<KodePos>> call, Response<ArrayList<KodePos>> response) {
            if (response.code()== 200){
                Log.i("bella", "onResponse: "+response);

                data = response.body();
                tempData = data;
                recyclerView.setHasFixedSize(true);
                recyclerView.addItemDecoration(new DividerItemDecoration(AddCustomerActivity.this, DividerItemDecoration.VERTICAL));
                recyclerView.setLayoutManager(new LinearLayoutManager(AddCustomerActivity.this));
                recyclerView.setAdapter(new KodePosAdapter(data));
            }
        }

        @Override
        public void onFailure(Call<ArrayList<KodePos>> call, Throwable t) {
            Toast.makeText(AddCustomerActivity.this, "Failed", Toast.LENGTH_SHORT).show();

        }
    });

    final AlertDialog alertDialog = dialogBuilder.create();
    alertDialog.show();

    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(AddCustomerActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            et_kodepos.setText(data.get(position).getPosKode());
            et_kota.setText(data.get(position).getPosKota());
            et_provinsi.setText(data.get(position).getPosProp());
            et_kecamatan.setText(data.get(position).getPosCamat());
            et_kelurahan.setText(data.get(position).getPosLurah());

            alertDialog.dismiss();
        }
    }));

}
 recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(AddCustomerActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {


        et_kodepos.setText(data.get(position).getPosKode());
        et_kota.setText(data.get(position).getPosKota());
        et_provinsi.setText(data.get(position).getPosProp());
        et_kecamatan.setText(data.get(position).getPosCamat());
        et_kelurahan.setText(data.get(position).getPosLurah());

    }

}));

在您的代码中,您每次都分配第 0 个(第一项)元素来编辑文本。