我只是创建一个带有循环视图的对话框。当我点击该项目时,它应根据我点击的内容设置编辑文本。但事实并非如此,它显示了循环视图中的第一个值。有人可以帮助我获得我点击的价值基础。我只是创建一个带有循环视图的对话框。当我点击该项目时,它应根据我点击的内容设置编辑文本。但事实并非如此,它显示了循环视图中的第一个值。有人可以帮助我获得我点击的价值基础
@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();
}
}));
}
答案 0 :(得分:0)
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个(第一个项目)元素来编辑文本。