Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Androidアプリを作る 第6回

nonylene
December 26, 2016

Androidアプリを作る 第6回

nonylene

December 26, 2016
Tweet

More Decks by nonylene

Other Decks in Technology

Transcript

  1. "OESPJEͷը૾ͷදݱ • Bitmap w ը૾Λද͢ • Drawable w ʮը໘ʹදࣔ͞ΕΔ΋ͷʯΛද͢ w

    ը૾͔΋͠Εͳ͍͠ɺͨͩͷ৭͔΋͠Εͳ͍ w ImageView΍എܠͰදࣔ͞ΕΔͷ͸͜Ε
  2. ը૾Λ഑ஔ • res/drawable/ ʹ Drawable Λઃஔ͢Δ w ࠓճ͸ը૾ 1/('JMF 

    w 9.-Ͱهड़͢Δ͜ͱ΋Մೳ w ௚઀ϑΝΠϧΛίϐʔ͢ΔPS
 "OESPJE4UVEJPܦ༝Ͱίϐʔ͢Δ ղ૾౓ผʹ࠷దͳը૾Λ༻ҙ͢Δ͜ͱ΋Ͱ͖Δ (drawable-hdpi ͳͲ)
  3. +BWBͰͷϨΠΞ΢τ w 9.-ʹॻ͍͍֤ͯͨView͸+BWBͷΫϥε • TextView -> android.widget.TextView • EditText ->

    android.widget.EditText
 • શͯ View ΫϥεͷࢠΫϥε XML Ͱ͸ android.widget ʹ͋Δ View ͸ಛผʹύοέʔδ໊ΛলུͰ͖͍ͯͨ.
 ಠࣗͷ View ͷ৔߹লུͰ͖ͳ͍.
  4. 7JFXΛऔಘ * MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText

    editText = (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button);
  5. * MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText editText

    = (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button); 7JFXΛऔಘ *%͕FEJU@UFYUͷ7JFXΛऔಘ
  6. * MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText editText

    = (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button); 7JFXΛऔಘ &EJU5FYUʹΩϟετͯ͠୅ೖ findViewById ͷฦΓ஋͸ View ݻఆͳͷͰΩϟετ͢Δඞཁ͕͋Δ
  7. * MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View

    v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ
  8. * MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View

    v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ 0O$MJDL-JTUFOFSͷແ໊ΦϒδΣΫτ
  9. * MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View

    v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ ΫϦοΫ͢Δͱݺ͹ΕΔؔ਺
  10. * MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View

    v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ τʔετΛදࣔ
  11. 4IBSFE1SFGFSFODF • σϑΥϧτͷ SharedPreferences Λऔಘ • ϑΝΠϧ͝ͱͷઃఆ (SharedPreference) 
 Λ؅ཧ͢ΔΫϥε

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Static ϝιου
  12. w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true) .apply();

    4IBSFE1SFGFSFODFT Ωʔͱ஋Λ֨ೲ put~~~ ͷฦΓ஋͸ editor ࣗ਎ͳͷͰ͜ͷΑ͏ʹॻ͚Δ ʢνΣʔϯϝιουͱ͍͏ʣ.
  13. w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true) .apply();

    4IBSFE1SFGFSFODFT ઃఆΛ൓ө commit() ͸ಉظతͰ͕͔͔࣌ؒΔͷͰඇਪ঑