嗨,我有一个适配器类,它在回收器中显示 editText,它工作正常,但我想做的是更改编辑文本显示的列表项位置,因为我使用数组它将第一项显示为"0", 那么我怎样才能让它从"1"开始计数,以便提示用户将饲料作为"项目 1"而不是以"项目 0"开头对我来说是有意义的。 为了保存信息,我使用了文本观察器。
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder>
{
private LayoutInflater inflater;
public static ArrayList<EditModel> editModelArrayList;
public CustomAdapter(Context ctx, ArrayList<EditModel> editModelArrayList){
inflater = LayoutInflater.from(ctx);
this.editModelArrayList = editModelArrayList;
}
@Override
public CustomAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.rv_item, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(final CustomAdapter.MyViewHolder holder, final int position) {
holder.editText.setText(" Item : "+editModelArrayList.get(position).getEditTextValue());
}
@Override
public int getItemCount() {
return editModelArrayList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder
{
protected EditText editText;
public MyViewHolder(View itemView) {
super(itemView);
editText = (EditText) itemView.findViewById(R.id.editid);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
editModelArrayList.get(getAdapterPosition()).setEditTextValue(editText.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
editModelArrayList.get(getAdapterPosition()).setEditTextValue(editText.getText().toString());
}
});
}
}
}
@Override
public void onBindViewHolder(final CustomAdapter.MyViewHolder holder, final
int position) {
holder.editText.setText(" Item : "+ (Integer.parseInt(editModelArrayList.get(position))+1));
}