• android 按钮点击测试


     
    package test2.com;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.*;
    
    public class Test2Activity extends Activity {
        /** Called when the activity is first created. */
    	//置于一个全局的TextView,
    	public TextView tv;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            
            Button start = (Button)findViewById(R.id.button1);
            Button finish = (Button)findViewById(R.id.button2);
            //把界面中的textView赋给tv
            tv =  (TextView)findViewById(R.id.textView2);
            TextView tv1 = (TextView)findViewById(R.id.textView2);
            
            start.setOnClickListener(new OnClickListener(){
    
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				//此时的tv是全局的,
    				tv.setText("start");
    				//tv1 在onCreate中产生的,所以下面的语句会抱错!!
    				//------------------//
    				//tv1.setText("inner Text");
    				//-------------------//
    				
    			}
            	
            });
            
            //
            finish.setOnClickListener(new View.OnClickListener() {
    			
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				tv.setText("finish");
    			}
    		});
            
            
            
        }
        
      
        
    }
    

    以上程序主代码

    在res/main.xml中加一个textview,2个button,分别设置text为start,stop
     
     

      点击start,stop分别显示start,stop  ,~~~~~~~


     

  • 相关阅读:
    vscode 缩进改为2空格
    js canvas图片压缩
    vue 父子组件通信
    vue prop 传递数据
    vue报错信息
    android.useDeprecatedNdk=true
    app:compileDebugNdk,NDK
    Kotlin来了
    design
    com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/ColorRes.class
  • 原文地址:https://www.cnblogs.com/flex_fly/p/2196421.html
Copyright © 2020-2023  润新知