Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Now Loading. Please Wait ...                Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
<?xml version="1.0" encoding="utf-8"?>                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/    ...
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
package ykmjuku.android.sample.app;   public class Calculater {       StringBuilder mInputNumber = new StringBuilder();   ...
private boolean isSupportedOperator(String key) {                if (key.equals("+")) {                    return true;   ...
private void doCalculation(String ope) {                if (ope.equals("+")) {                    mResult = mResult + Inte...
public String putInput(String key) {               if (isNumber(key)) {                   mInputNumber.append(key);       ...
(bit)                boolean   1              true/false      FALSE                 char     16             0   FFFF      ...
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
try {                    Integer.parseInt(key);                    return true;                } catch (NumberFormatExcept...
Ykmjuku002Activity                                ”OK”                                       Re:Kayo-System Co.,Ltd.2012  ...
package ykmjuku.android.sample.app;   import       android.app.Activity;   import       android.os.Bundle;   import       ...
/** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {       ...
public void afterTextChanged(Editable s) {                 String input = s.toString();                 Log.d("Ykmjuku002A...
public void onClick(View v) {                    String dispText = mCalculater.putInput("=");                    if(dispTe...
Re:Kayo-System Co.,Ltd.2012   2   22
Re:Kayo-System Co.,Ltd.2012   2   22
Upcoming SlideShare
Loading in …5
×

夜子まま塾講義3(androidで電卓アプリを作る)

8,647 views

Published on

電卓アプリを題材にAndroidプロジェクトの作成からクラスの編集まで

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

夜子まま塾講義3(androidで電卓アプリを作る)

  1. 1. Now Loading. Please Wait ... Re:Kayo-System Co.,Ltd.2012 2 22
  2. 2. Re:Kayo-System Co.,Ltd.2012 2 22
  3. 3. Re:Kayo-System Co.,Ltd.2012 2 22
  4. 4. Re:Kayo-System Co.,Ltd.2012 2 22
  5. 5. Re:Kayo-System Co.,Ltd.2012 2 22
  6. 6. Re:Kayo-System Co.,Ltd.2012 2 22
  7. 7. Re:Kayo-System Co.,Ltd.2012 2 22
  8. 8. Re:Kayo-System Co.,Ltd.2012 2 22
  9. 9. Re:Kayo-System Co.,Ltd.2012 2 22
  10. 10. Re:Kayo-System Co.,Ltd.2012 2 22
  11. 11. Re:Kayo-System Co.,Ltd.2012 2 22
  12. 12. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> Re:Kayo-System Co.,Ltd.2012 2 22
  13. 13. Re:Kayo-System Co.,Ltd.2012 2 22
  14. 14. Re:Kayo-System Co.,Ltd.2012 2 22
  15. 15. Re:Kayo-System Co.,Ltd.2012 2 22
  16. 16. Re:Kayo-System Co.,Ltd.2012 2 22
  17. 17. Re:Kayo-System Co.,Ltd.2012 2 22
  18. 18. Re:Kayo-System Co.,Ltd.2012 2 22
  19. 19. package ykmjuku.android.sample.app; public class Calculater { StringBuilder mInputNumber = new StringBuilder(); String mOperator; int mResult = 0; private boolean isNumber(String key) { try { Integer.parseInt(key); return true; } catch (NumberFormatException e) { } return false; } Re:Kayo-System Co.,Ltd.2012 2 22
  20. 20. private boolean isSupportedOperator(String key) { if (key.equals("+")) { return true; } else if (key.equals("-")) { return true; } else if (key.equals("*")) { return true; } else if (key.equals("/")) { return true; } return false; } Re:Kayo-System Co.,Ltd.2012 2 22
  21. 21. private void doCalculation(String ope) { if (ope.equals("+")) { mResult = mResult + Integer.parseInt(mInputNumber.toString()); } else if (ope.equals("-")) { mResult = mResult - Integer.parseInt(mInputNumber.toString()); } else if (ope.equals("*")) { mResult = mResult * Integer.parseInt(mInputNumber.toString()); } else if (ope.equals("/")) { mResult = mResult / Integer.parseInt(mInputNumber.toString()); } mInputNumber = new StringBuilder(); } Re:Kayo-System Co.,Ltd.2012 2 22
  22. 22. public String putInput(String key) { if (isNumber(key)) { mInputNumber.append(key); return mInputNumber.toString(); } else if (isSupportedOperator(key)) { if (mOperator != null) { doCalculation(mOperator); mOperator = null; } else if (mInputNumber.length() > 0) { mResult = Integer.parseInt(mInputNumber.toString()); mInputNumber = new StringBuilder(); } mOperator = key; return mOperator; } else if (key.equals("=")) { if (mOperator != null) { doCalculation(mOperator); mOperator = null; } return Integer.toString(mResult); } else { // return null; } } } Re:Kayo-System Co.,Ltd.2012 2 22
  23. 23. (bit) boolean 1 true/false FALSE char 16 0 FFFF 0 byte 8 -128 127 0 short 16 -32768 32767 0 int 32 0 long 64 0 float 32 0.0 double 64 0.0 Re:Kayo-System Co.,Ltd.2012 2 22
  24. 24. Re:Kayo-System Co.,Ltd.2012 2 22
  25. 25. Re:Kayo-System Co.,Ltd.2012 2 22
  26. 26. try { Integer.parseInt(key); return true; } catch (NumberFormatException e) { } return false; Re:Kayo-System Co.,Ltd.2012 2 22
  27. 27. Ykmjuku002Activity ”OK” Re:Kayo-System Co.,Ltd.2012 2 22
  28. 28. package ykmjuku.android.sample.app; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Ykmjuku002Activity extends Activity implements TextWatcher, OnClickListener { EditText mEditText1; TextView mTextView1; Button mButton1; Calculater mCalculater = new Calculater(); Re:Kayo-System Co.,Ltd.2012 2 22
  29. 29. /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView1 = (TextView)findViewById(R.id.textView1); mEditText1 = (EditText)findViewById(R.id.editText1); mButton1 = (Button)findViewById(R.id.button1); mEditText1.addTextChangedListener(this); mButton1.setOnClickListener(this); } Re:Kayo-System Co.,Ltd.2012 2 22
  30. 30. public void afterTextChanged(Editable s) { String input = s.toString(); Log.d("Ykmjuku002Activity", "input="+input); if(input.length()>0){ String dispText = mCalculater.putInput(input); if(dispText!=null){ mTextView1.setText(dispText); } s.clear(); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } Re:Kayo-System Co.,Ltd.2012 2 22
  31. 31. public void onClick(View v) { String dispText = mCalculater.putInput("="); if(dispText!=null){ mTextView1.setText(dispText); } mEditText1.setText(null); } } Re:Kayo-System Co.,Ltd.2012 2 22
  32. 32. Re:Kayo-System Co.,Ltd.2012 2 22
  33. 33. Re:Kayo-System Co.,Ltd.2012 2 22

×