• android基础(Activity)


    package ahu.edu;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class Activity03Activity extends Activity {
    	
    
    	
    	private EditText factorOne;
    	private EditText factorTwo;
    	private TextView symbol;
    	private Button calculate;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            factorOne = (EditText)findViewById(R.id.factorOne);
            factorTwo = (EditText)findViewById(R.id.factorTwo);
            symbol = (TextView)findViewById(R.id.symbol);
            calculate = (Button)findViewById(R.id.calculate);
            symbol.setText(R.string.symbol);
            calculate.setText(R.string.calculate);
            calculate.setOnClickListener(new CalcualteListener());
        }
        
        class CalcualteListener implements OnClickListener {
        	public void onClick(View v) {
        		String factorOneStr = factorOne.getText().toString();
        		String factorTwoStr = factorTwo.getText().toString();
        		Intent intent = new Intent();
        		intent.putExtra("one", factorOneStr);
        		intent.putExtra("two", factorTwoStr);
        		intent.setClass(Activity03Activity.this,ResualActivity.class);
        		Activity03Activity.this.startActivity(intent);
        	}
        }
        
    	public boolean onCreateOptionsMenu(Menu menu) {
    		menu.add(0, 1, 1,R.string.exit);
    		menu.add(0, 2, 2,R.string.about);
    		return super.onCreateOptionsMenu(menu);
    	}
    	
    	public boolean onOptionsItemSelected(MenuItem item) {
    		if(item.getItemId() == 1) {
    			//finish();  //----比较柔和的方式
    			System.exit(0); //---残酷的方式
    		}
    		return super.onOptionsItemSelected(item);
    	}
    
    }
    package ahu.edu;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class ResualActivity extends Activity{
    	private TextView resultView;
    	
    	
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.result);
    		resultView = (TextView)findViewById(R.id.result);
    		Intent intent = getIntent();
    		String factorOneString = intent.getStringExtra("one");
    		String factorTwoString = intent.getStringExtra("two");
    		int factorOneInt = Integer.parseInt(factorOneString);
    		int factorTwoInt = Integer.parseInt(factorTwoString);
    		int result = factorOneInt * factorTwoInt;
    		resultView.setText(result + "");
    	}
    }
    

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        <EditText 
            android:id="@+id/factorOne"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/message" 
            android:inputType="none"/>
        <TextView 
            android:id="@+id/symbol"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""/>
        <EditText 
            android:id="@+id/factorTwo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/message" 
            android:inputType="none"/>
        <Button 
           	android:id="@+id/calculate"
           	android:layout_width="fill_parent"
           	android:layout_height="wrap_content"
           	/>
        	
      
    </LinearLayout>

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="ahu.edu"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk android:minSdkVersion="10" />
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".Activity03Activity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity 
                android:name=".ResualActivity"
                android:label="@string/app_name">
                
            </activity>
        </application>
    
    </manifest>


  • 相关阅读:
    DotNetCore + Sonar + Coverlet 代码覆盖率检查
    Docker + Sonarqube 环境搭建
    使用cmd进行tfs的签入
    Swashbuckle.AspNetCore(v2.5.0)使用小记
    Ocelot(v7.0.6)使用小记
    layui.formSelects.render(); 需要先执行
    .net core编译时设置不自动生成“netcoreapp3.0”目录
    C# List引用类型的克隆
    HTTP Error 502.5
    GPS服务端(上)-Socket服务端(golang)
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671606.html
Copyright © 2020-2023  润新知