我使用了一个菜单充气器,并且在每一行中,我都给 textview 和 seekbar 一个 id 的 i(我使用一个 for 循环来给他们 id)。当我得到 seekbar 的 id 并且我想将文本插入到 textview 中时。我遇到的问题是如何在文本视图中设置与搜索栏具有相同值的文本。
public static void setNewTipAmount(SeekBar barChanged, double amountForTip) {
int getID = barChanged.getId(); //get seekbar id
TextView textView = tipPerPerson.findViewById(getID);// get the textview with same id
textView.setText("Hello");
}
}
这是我如何分配 ID 的代码
for (int i = 0; i < InBetweenUIAndBusinessLogic.getGuests(); i++) {
View v = in.inflate(R.layout.row_per_person, table, false);
double tipPerIndividual = (Math.round(InBetweenUIAndBusinessLogic
.getTipPerPerson() * 100.0) / 100.0);
String tip = Double.toString(tipPerIndividual);
tipPerPerson = (TextView) v.findViewById(R.id.tipPerPerson);
tipPerPerson.setId(i);
tipPerPerson.setText(tip);
rows.add(tipPerPerson);
percentageTip = (SeekBar) v.findViewById(R.id.seekBar1);
percentageTip.setOnSeekBarChangeListener(new myListener());
double guests = InBetweenUIAndBusinessLogic.getGuests();
percentageTip.setProgress((int) (100 / guests));
percentageTip.setId(i);
table.addView(v);
bars.add(percentageTip);
}