Android乘法计算器

Calculate.java

public class Calculate extends Activity {
	private Button myCalculate=null;
	private EditText factorone=null;
	private EditText factortwo=null;
	private TextView myMultiply=null;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        factorone = (EditText)findViewById(R.id.factorone);
        myMultiply = (TextView)findViewById(R.id.myMultiply);
        factortwo = (EditText)findViewById(R.id.factortwo);
        myCalculate = (Button)findViewById(R.id.myCalculate);
        
        myMultiply.setText(R.string.multiply);
        myCalculate.setText(R.string.calculate);
        myCalculate.setOnClickListener(new myCalculateOnClickListener());
    }
    
    class myCalculateOnClickListener implements OnClickListener {
		@Override
		public void onClick(View arg0) {
			String factoroneStr = factorone.getText().toString();
			String factortwoStr = factortwo.getText().toString();
			Intent intent = new Intent();
			intent.putExtra("one", factoroneStr);
			intent.putExtra("two",factortwoStr);
			intent.setClass(Calculate.this, Result.class);
		
		    Calculate.this.startActivity(intent);
		}
    }
}

result.java

public class Result extends Activity {
	private TextView myResult;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.result);
		myResult = (TextView)findViewById(R.id.myResult);
		Intent intent = getIntent();
		String factoroneStr = intent.getStringExtra("one");
		String factortwoStr = intent.getStringExtra("two");
		int factoroneInt = Integer.parseInt(factoroneStr);
		int factortwoInt = Integer.parseInt(factortwoStr);
		int calresult = factoroneInt * factortwoInt;
		myResult.setText(calresult + "");
	}
}

main.xml

result.xml

string.xml

暂无评论
  • 1:请一针见血的评论。
  • 2:评论需要审核通过后才能显示。
  • 3:评论字数限制在1000字以内。
  • 当前字数:0
热门文章
推荐文章
随机文章
关于本站 - 广告服务 - 版权声明 - 联系我们 - 友情链接 - 网站地图 - 帮助中心