我正在制作一个账单拆分器,并且试图创建一个RecyclerView,其中包含代表您要与之拆分账单的组中人员的项目。我想使用搜索栏来更改一个人必须支付的账单百分比。
基本设计图片:
举例来说,我将A人的搜索栏进度从25%更改为79%,然后我希望B,C和D人的搜索栏进度为7%,因为100%-79%= 21%/ 3人= 7%
更改后的图片
问题是,当我更改Person A的搜索杆进度时,我不知道如何更改其他搜索杆进度。
这是我的代码:
public class PersonListAdapter extends RecyclerView.Adapter<PersonListAdapter.PersonListViewHolder> {
private ArrayList<Person> mPersonList = new ArrayList<>();
public class PersonListViewHolder extends RecyclerView.ViewHolder {
TextView mPersonText, mMoneyText, mPercentageText;
SeekBar mPercentageSeekbar;
MaterialAnimatedSwitch mLockSwitch;
public PersonListViewHolder(final View itemView) {
super(itemView);
mPersonText = itemView.findViewById(R.id.person_name_text);
mMoneyText = itemView.findViewById(R.id.money_text);
mPercentageText = itemView.findViewById(R.id.money_percentage_text);
mPercentageSeekbar = itemView.findViewById(R.id.money_seekbar);
mLockSwitch = itemView.findViewById(R.id.lock_switch);
}
}
public PersonListAdapter(int billTotal, int persons) {
for (int i = 0; i < persons; i++) {
// simulating values
mPersonList.add(new Person('a', new BigDecimal(10), 10));
}
}
@NonNull
@Override
public PersonListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.person_item, parent, false);
return new PersonListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final PersonListViewHolder holder, int position) {
final Person person = mPersonList.get(position);
holder.mPersonText.setText("Person " + person.name.toString().toUpperCase());
holder.mMoneyText.setText("$" + String.valueOf(person.money));
holder.mPercentageText.setText(String.valueOf(person.percentage) + "%");
holder.mPercentageSeekbar.setProgress(Integer.valueOf(person.percentage.setScale(0, RoundingMode.HALF_UP).toString()));
holder.mPercentageSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
// What to do???
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
@Override
public int getItemCount() {
return mPersonList.size();
}
class Person {
Character name;
BigDecimal money;
int percentage;
Person(Character name, BigDecimal money, int percentage) {
this.name = name;
this.money = money;
this.percentage = percentage;
}
public void setPercentage(int percentage) {
this.percentage = percentage;
}
}
}