Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何自动生成总金额?_Android_Xml - Fatal编程技术网

Android 如何自动生成总金额?

Android 如何自动生成总金额?,android,xml,Android,Xml,我是android新手,我正在尝试在用户在我的购买页面中输入数量后自动生成总金额。我首先从另一个活动中获取产品价格,然后编辑文本以获取数量。之后,页面将自动显示总金额。有没有人有这样做的经验 我的代码: 公共类PageBuy扩展活动{ 文本视图lblPID; 文本视图lblName; 文本视图lblAmount; 编辑文本数量; 整数总金额; 私有静态最终字符串密钥\u ERROR\u MSG=“ERROR\u MSG”; 私有静态最终字符串TAG_NAME=“product_NAME”; 私有

我是android新手,我正在尝试在用户在我的购买页面中输入数量后自动生成总金额。我首先从另一个活动中获取产品价格,然后编辑文本以获取数量。之后,页面将自动显示总金额。有没有人有这样做的经验

我的代码:

公共类PageBuy扩展活动{
文本视图lblPID;
文本视图lblName;
文本视图lblAmount;
编辑文本数量;
整数总金额;
私有静态最终字符串密钥\u ERROR\u MSG=“ERROR\u MSG”;
私有静态最终字符串TAG_NAME=“product_NAME”;
私有静态最终字符串标记\u PID=“产品\u id”;
私有静态最终字符串标记\u AMOUNT=“AMOUNT”;
私有静态最终字符串键\u QUANTITY=“QUANTITY”;
私有静态最终字符串键\u UID=“UID”;
私有静态最终字符串密钥\u CREATED\u AT=“CREATED\u AT”;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.pagebuy);
Intent gg=getIntent();
字符串产品id=gg.getStringExtra(标记PID);
字符串product\u name=gg.getStringExtra(标记名称);
字符串金额=gg.getStringExtra(标记金额);
lblPID=(TextView)findViewById(R.id.product\u id\u标签);
lblName=(TextView)findViewById(R.id.product\u name\u label);
lblAmount=(TextView)findViewById(R.id.amount\U标签);
lblPID.setText(产品标识);
lblName.setText(产品名称);
lblAmount.setText(金额);
数量=(EditText)findViewById(R.id.quantity);
字符串quan=quantity.getText().toString().trim();
System.out.println(quan+“Short”);
//UserFunctions userFunction=新的UserFunctions();
//JSONObject json=userFunction.rebuy(产品id、金额、数量);
按钮btn_确认=(按钮)findViewById(R.id.btn_确认);
按钮btn\U home=(按钮)findViewById(R.id.btn\U home);
btn_confirm.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图){
DatabaseHandler db=新的DatabaseHandler(getApplicationContext());
字符串uid=db.getCurrentId();
System.out.println(“SHORTALEX”+uid);
字符串product_id=lblPID.getText().toString().trim();
字符串金额=lblAmount.getText().toString();
字符串quan=quantity.getText().toString().trim();
UserFunctions userFunction=新的UserFunctions();
JSONObject json=userFunction.rebuy(产品id、金额、数量、uid);
//DatabaseHandler2 db=新的DatabaseHandler2(getApplicationContext());
JSONObject json_用户;
试试{
System.out.println(“SHORTY”);
System.out.println(json.toString());
json_user=json.getJSONObject(“userbuy”);
}捕获(JSONException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
Toast.makeText(PageBuy.this,“购买成功”,Toast.LENGTH_SHORT.show();
Intent i=新Intent(getApplicationContext(),PagePurchaseRecord.class);
星触觉(i);
}               
});
btn_home.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图){
Intent i=新Intent(getApplicationContext(),Main.class);
星触觉(i);
}
});     
}
}

您需要textwatcher来执行此操作

            quantity.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // update quanttiti here

                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub

                }
            });

不要使用
System.out.println
,使用
android.util.Log