final EditText inputServer = new EditText(adapterActivity); AlertDialog.Builder builder = new AlertDialog.Builder(adapterActivity); builder.setTitle("请输入数量").setIcon(android.R.drawable.ic_dialog_info).setView(inputServer) .setNegativeButton("取消", null); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { if(t.getNum()>0) sum-=t.getNum()*t.getVal(); sum+=Integer.parseInt(inputServer.getText().toString())*t.getVal(); btn.setText(String.format("由以上食物您将摄取的总热量为:%d卡路里",sum)); adapterlist.get(position).setNum(Integer.parseInt(inputServer.getText().toString())); onBindViewHolder(holder,position); } }); builder.show();