• 控件变运算符的方法??---加法运算+


    package com.example.sum;//sum
    
    import com.example.sum.R;//sum
    
    
    //import com.example.hello.R;
    
    import android.app.Activity;
    import android.view.View.OnClickListener;
    import android.os.Bundle;
    //import android.view.Menu;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    //import android.view.Menu;
    import android.view.View;
    //import android.widget.Button;
    //import android.widget.EditText;
    //import android.widget.TextView;//导入各种包
    
    
    
    public class MainActivity extends Activity {
        
    
            
            
            
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main); 
         
            final Button button1 = (Button) findViewById(R.id.button1);//final获得句柄 获得句柄
            final  Button button2 = (Button) findViewById(R.id.button2);
            final  EditText editText1 = (EditText) findViewById(R.id.editText1);
            final    EditText editText2 = (EditText) findViewById(R.id.editText2);
            final  EditText editText3 = (EditText) findViewById(R.id.editText3);
            final   TextView textView =  (TextView) findViewById(R.id.textView1);    
            
            
            button1.setOnClickListener(new OnClickListener()
            { 
               public void onClick(View v)
               {        
      
                   String a=editText3.getText().toString().trim();//判断编辑框3是否为字符串加号 赋值
                   String b="+";
                   
                   
                   if (a.equals(b)){//如果编辑框3为字符串加号,那么执行加法运算 字符串比较
                       
                       
                       
                       textView.setText(String.valueOf(
                               Integer.parseInt(editText1.getText().toString().trim())   //控件转字符串,字符串转整形,整形转字符串
                              +Integer.parseInt(editText2.getText().toString().trim())   //去除空格
                       
                               ));
                                
                   }else{ System.out.println("A");        }
                   
                   
               }
            });
            
          
            //+Integer.parseFloa(editText3.getText().toString().trim())        
            
            button2.setOnClickListener(new OnClickListener()
            { 
               public void onClick(View v)
               {
                   
                  
                      editText3.setText(button2.getText());
                        
               }
            });
            
            
            }
        
    
        
    
     
        
        
        
        
    }
  • 相关阅读:
    [Swift]GZip字符串压缩和解压缩(Java/C#通用)
    [XCode]UI测试/单元测试
    转 oracle apex 使用
    转 pygame学习笔记(1)——安装及矩形、圆型画图
    转 11g RAC R2 体系结构---Grid
    转如何升级oracle版本?(11.2.0.1至11.2.0.4)
    ORA-14074: partition bound must collate higher than that of the last partition
    12c pdb expdp use DATA_PUMP_DIR meet ORA-39145
    转【Python】Python-skier游戏[摘自.与孩子一起学编程]
    Dock
  • 原文地址:https://www.cnblogs.com/hellowzd/p/4224446.html
Copyright © 2020-2023  润新知