我想做的是在 TableLayout 中显示一个复选框、一个按钮和一个微调器。这些值是从 Web 服务获取的,并且 tableRows 会动态添加到 TableLayout。
第一个按钮创建一个带有列表视图的对话框。列表视图包含数字 1-30。当用户单击在 ListView 中选择一个值时,我需要将按钮的文本更改为单击的值。该代码适用于单击的第一个按钮(第一次打开列表视图并选择一个值时,按钮的文本会更改)。但是第二次打开列表视图并选择一个按钮时,第一个按钮的文本会发生变化,而不是被点击的那个。我究竟做错了什么?
protected void fillTableView() {
for (MedicineInfo temp : orderedMedList) {
LayoutInflater inflater = getLayoutInflater();
TableRow tr = (TableRow) inflater.inflate(
R.layout.neworderrestockmedicinelist2, tlOrderInfo, false);
CheckBox cbMedicine = (CheckBox) tr
.findViewById(R.id.cbNewOrderRestockMedName);
cbMedicine.setText(temp.vcProduct);
Button btnQty = (Button) tr
.findViewById(R.id.btnNewOrderRestockQty);
Spinner spnIntakeUnit = (Spinner) tr
.findViewById(R.id.spnNewOrderRestockIntakeUnit);
IntakeUnitAdapter intakeUnitAda = new IntakeUnitAdapter(this);
spnIntakeUnit.setAdapter(intakeUnitAda);
ArrayAdapter<String> arrayAda = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, numberArray);
arrayAda.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
tlOrderInfo.addView(tr);
btnQty.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
dlgQty = new Dialog(mContext);
TableRow tr = (TableRow) v.getParent();
ListView lvQty = new ListView(mContext);
QuantityAdapter qtyAda = new QuantityAdapter(mContext);
lvQty.setAdapter(qtyAda);
dlgQty.addContentView(lvQty,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ItemSelectTest test = new ItemSelectTest(tr);
lvQty.setOnItemClickListener(test);
showDialog(DLG_QTY);
test = null;
}
});
}
}
private class ItemSelectTest implements OnItemClickListener {
Button btn = null;
public ItemSelectTest(TableRow tr) {
Button bt = (Button) tr.findViewById(R.id.btnNewOrderRestockQty);
btn = bt;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
btn.setText(String.valueOf(arg3));
}
}
In the same shown above, i'm passing the TableRow that contains the button. I've also tried passing v from onClick. The problem is the same either way..
Thanks