チェックが変更されたときにチェックボックスで問題が発生し、チェックボックスがチェックされている場合、入力値を取得して値をテキストビューに設定するアラートダイアログを表示し、その値をここのリストに追加するのは私のコードです
@Override
public void onCheckedChanged(CompoundButton checkBox, boolean isChecked)
{
TextView tvItem=(TextView)selectedView.findViewById(R.id.foodName);
final TextView tvQuantity=(TextView)selectedView.findViewById(R.id.quantity);
orderList=new ArrayList<Order>();
Order order=new Order();
if(isChecked)
{
final AlertDialog.Builder quantityAlert= new AlertDialog.Builder(TakeOrder.this);
quantityAlert.setTitle("Quantity");
quantityAlert.setMessage("Please enter quantity");
final EditText input = new EditText(TakeOrder.this);
input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
quantityAlert.setView(input);
quantityAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
value = input.getText();
tvQuantity.setText(value);
}
});
quantityAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
});
quantityAlert.show();
order.setItem(tvItem.getText().toString());
order.setQuantity(Integer.valueOf(tvQuantity.getText().toString()));
orderList.add(selectedPosition, order);
Log.v("Item:",orderList.get(selectedPosition).getItem());
Log.v("Quantity:",String.valueOf(orderList.get(selectedPosition).getQuantity()));
}
else
{
tvQuantity.setText("0");
orderList.remove(selectedPosition);
}
}
問題は、最初にアラートダイアログを表示してから、ユーザーから数量の値を取得することですが、アラートボックスに値を入力する前に、Log.vが実行され、0が表示されます。これは、リストの数量が0に追加されていることを意味します...しかしアラートダイアログからの数量値をリストに追加したいのですが...誰か助けてくれませんか...