gpt4 book ai didi

android - Recyclerview 中的多个编辑文本

转载 作者:行者123 更新时间:2023-11-29 14:46:40 31 4
gpt4 key购买 nike

我们正在开发一款可以分摊团体费用的应用程序。为此,您可以选择您希望与其分享下一份账单的人。我制作了一种“ ListView 项目”,其中包含每个用户的“借方”和“贷方”字段,并根据共享付款的人数将这些项目添加到 Recyclerview。但是,现在我正在尝试读取在这些编辑文本中输入的所有值,但我不知道如何读取。在 recyclerview 中生成列表的代码如下:

private void initRecyclerView() {
rvTransactions = (RecyclerView) findViewById(R.id.rvTransactions);
lmTransactions = new LinearLayoutManager(this);
rvTransactions.setLayoutManager(lmTransactions);
transactionAdapter = new RecyclerView.Adapter<CustomViewHolder>() {
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item_transaction, viewGroup, false);
return new CustomViewHolder(view);
}

@Override
public void onBindViewHolder(CustomViewHolder viewHolder, int i) {
viewHolder.noticeSubject.setText(participatingUsers.get(i).getFirstname() + " " + participatingUsers.get(i).getLastname());
}

@Override
public int getItemCount() {
return participatingUsers.size();
}

};
rvTransactions.setAdapter(transactionAdapter);
}

private class CustomViewHolder extends RecyclerView.ViewHolder {

private TextView noticeSubject;
private EditText userDebt,userCredit;

public CustomViewHolder(View itemView) {
super(itemView);

noticeSubject = (TextView) itemView.findViewById(R.id.tvTransactionUser);
userCredit = (EditText) findViewById(R.id.etTransactionPayed);
userDebt = (EditText) findViewById(R.id.etTransactionOwes);
}
}

participatingUsers 对象是一个用户列表。用户具有以下字段:

private int id;
private boolean isSelected;
private String firstname, lastname, email, password, api_key, creditcardnumber;

This is what the view looks like, you can see the "payed" and "owes" fields that were added dynamicly

我希望能够为所有用户获取在编辑文本“已支付”和“欠款”中输入的值。

最佳答案

循环遍历 RecyclerView 的 childCount 并检查以确保您阅读的项目是 CustomViewHolder 类型,转换为该类型并读取 EditText 值。像这样的东西:

 public void printAllEditTextValues(){
int childCount = rvTransactions.getChildCount();
for(int i = 0; i < childCount; i++){
if(rvTransactions.findViewHolderForLayoutPosition(i) instanceOf CustomViewHolder){
CustomViewHolder childHolder = (CustomViewHolder) rvTransactions.findViewHolderForLayoutPosition(i);

Log.d("EDIT_TEXT_1" , childHolder.userCredit.getText().toString());
Log.d("EDIT_TEXT_2" , childHolder.userDebt.getText().toString());
}
}

您的适配器缺少用于编辑文本的 itemView.findViewById(int),请使用:

private class CustomViewHolder extends RecyclerView.ViewHolder {

private TextView noticeSubject;
private EditText userDebt,userCredit;

public CustomViewHolder(View itemView) {
super(itemView);

noticeSubject = (TextView) itemView.findViewById(R.id.tvTransactionUser);
userCredit = (EditText) itemView.findViewById(R.id.etTransactionPayed);
userDebt = (EditText) itemView.findViewById(R.id.etTransactionOwes);
}
}

关于android - Recyclerview 中的多个编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283734/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com