{"id":780,"date":"2023-03-14T16:43:52","date_gmt":"2023-03-14T07:43:52","guid":{"rendered":"https:\/\/www.dogrow.net\/android\/?p=780"},"modified":"2023-03-15T05:42:22","modified_gmt":"2023-03-14T20:42:22","slug":"blog40","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/android\/blog40\/","title":{"rendered":"(40) \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u5207\u308a\u66ff\u3048\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6e21\u3059\u3002"},"content":{"rendered":"<h1 class=\"my_h\">0. \u95a2\u9023\u6295\u7a3f<\/h1>\n<p><a href=\"https:\/\/www.dogrow.net\/android\/blog39\/\" target=\"_blank\" rel=\"noopener\">(39) \u30a2\u30d7\u30ea\u306e\u753b\u9762\u5207\u308a\u66ff\u3048\u3092\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u306e\u5909\u66f4\u3067\u5b9f\u73fe\u3059\u308b\u3002<\/a><br \/>\n<a href=\"https:\/\/www.dogrow.net\/android\/blog40\/\" target=\"_blank\" rel=\"noopener\">(40) \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u5207\u308a\u66ff\u3048\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6e21\u3059\u3002<\/a> <b>\u2190\u672c\u6295\u7a3f<\/b><br \/>\n<a href=\"https:\/\/www.dogrow.net\/android\/blog41\/\" target=\"_blank\" rel=\"noopener\">(41) \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u7d42\u4e86\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u623b\u3059\u3002<\/a><\/p>\n<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>Android\u30a2\u30d7\u30ea\u306e\u753b\u9762\u5207\u308a\u66ff\u3048\u6642\u3001\u3059\u306a\u308f\u3061\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u306e\u5207\u308a\u66ff\u3048\u6642\u306b\u3001\u9077\u79fb\u5143\u304b\u3089\u9077\u79fb\u5148\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6e21\u3057\u305f\u3044\u3002<\/p>\n<p>\u4eca\u56de\u306f <span class=\"my_fc_deeppinkBBig\">\u5f80\u8def<\/span> \u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u304a\u304f\u3002<br \/>\n<span class=\"my_fc_blueBBig\">\u5fa9\u8def<\/span> \u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u53d7\u3051\u6e21\u3057\u306b\u3064\u3044\u3066\u306f\u3001\u6b21\u6295\u7a3f\u4ee5\u964d\u306b\u66f8\u304f\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b \u5165\u9580\u7de8 : \u5358\u7d14\u306a\u30c7\u30fc\u30bf\u306e\u53d7\u3051\u6e21\u3057<\/h1>\n<p>Android developers\u516c\u5f0f\u30b5\u30a4\u30c8\u306b\u624b\u9806\u304c\u4e01\u5be7\u306b\u8aac\u660e\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u305a\u306f\u305d\u3061\u3089\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u3002<br \/>\n<a href=\"https:\/\/developer.android.com\/training\/basics\/firstapp\/starting-activity?hl=ja\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.android.com\/training\/basics\/firstapp\/starting-activity?hl=ja<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/android\/wp-content\/uploads\/2023\/03\/Image3.jpg\" alt=\"\"  \/><\/a><\/p>\n<p>\u672c\u6295\u7a3f\u3067\u306f\u3001\u524d\u6295\u7a3f <a href=\"https:\/\/www.dogrow.net\/android\/blog39\/\" target=\"_blank\" rel=\"noopener\">(39) \u30a2\u30d7\u30ea\u306e\u753b\u9762\u5207\u308a\u66ff\u3048\u3092\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u306e\u5909\u66f4\u3067\u5b9f\u73fe\u3059\u308b\u3002<\/a> \u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u53d7\u3051\u6e21\u3057\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<h3 class=\"my_h\">(1) MainActivity.java<\/h3>\n<p>SubActivity\u3078\u306e\u5207\u308a\u66ff\u3048\u6642\u306b\u3001EditText\u306b\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u3092\u6e21\u3059\u3088\u3046\u306b\u6539\u9020\u3057\u305f\u3002<br \/>\n\u5177\u4f53\u7684\u306b\u306f <span class=\"my_fc_deeppinkB\">putExtra<\/span> \u3067 Intent\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u57cb\u3081\u8fbc\u3080\u3002<\/p>\n<pre class=\"brush: java; highlight: [7,8]; title: ; notranslate\" title=\"\">\r\n   @Override\r\n    public boolean onTouchEvent(MotionEvent event) {\r\n        if(event.getAction() == MotionEvent.ACTION_UP) {\r\n            EditText et = findViewById(R.id.et_textMain);\r\n            String txt = et.getText().toString();\r\n            \/\/ EditText\u306b\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u3092\u3001\u5207\u308a\u66ff\u3048\u5148\u306e\u753b\u9762\u306b\u6e21\u3059\u60c5\u5831\u3068\u3057\u3066\u30bb\u30c3\u30c8\r\n            Intent intent = new Intent(getApplicationContext(), SubActivity.class);\r\n            intent.putExtra(&quot;param&quot;, txt);\r\n\r\n            \/\/ \u753b\u9762\u5207\u308a\u66ff\u3048\u3092\u5b9f\u884c\r\n            startActivity(intent);\r\n        }\r\n        return super.onTouchEvent(event);\r\n    }\r\n<\/pre>\n<h3 class=\"my_h\">(2) SubActivity.java<\/h3>\n<p>SubActivity\u306e\u751f\u6210\u6642\u306b\u3001\u53d7\u3051\u6e21\u3055\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d6\u308a\u51fa\u3057\u3001EditText\u306e\u521d\u671f\u5024\u3068\u3059\u308b\u3002<br \/>\n\u5177\u4f53\u7684\u306b\u306f <span class=\"my_fc_deeppinkB\">getStringExtra<\/span>, <span class=\"my_fc_deeppinkB\">getIntExtra<\/span> \u3067 Intent\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d6\u308a\u51fa\u3059\u3002<\/p>\n<pre class=\"brush: java; highlight: [7,8]; title: ; notranslate\" title=\"\">\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_sub);\r\n\r\n        \/\/ \u5207\u308a\u66ff\u3048\u5143\u753b\u9762\u304b\u3089\u6e21\u3055\u308c\u305f\u60c5\u5831\u3092 EditText\u306b\u8a2d\u5b9a\u3059\u308b\u3002\r\n        Intent intent = getIntent();\r\n        String txt = intent.getStringExtra(&quot;param&quot;);\r\n        EditText et = findViewById(R.id.et_textSub);\r\n        et.setText(txt);\r\n    }\r\n\r\n<\/pre>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b \u5fdc\u7528\u7de8 : \u8907\u96d1\u306a\u30c7\u30fc\u30bf\u306e\u53d7\u3051\u6e21\u3057<\/h1>\n<p><span class=\"my_fc_deeppinkB\">Serializable<\/span> \u307e\u305f\u306f <span class=\"my_fc_deeppinkB\">Parcelable<\/span> \u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u305f\u30af\u30e9\u30b9\u3067\u3042\u308c\u3070\u3001\u305d\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<h3 class=\"my_h\">(1) MyParam.java<\/h3>\n<p>\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u53d7\u3051\u6e21\u3057\u306b\u4f7f\u308f\u308c\u308b\u30af\u30e9\u30b9\u3002<br \/>\n<span class=\"my_fc_deeppinkB\">Serializable<\/span> interface\u3092\u5b9f\u88c5\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage com.example.testchangescreen;\r\n\r\nimport java.io.Serializable;\r\n\r\npublic class MyParam implements Serializable {\r\n    private String txt;\r\n    private int num;\r\n\r\n    public MyParam(String txt, int num){\r\n        this.txt = txt;\r\n        this.num = num;\r\n    }\r\n\r\n    public String getTxt(){\r\n        return this.txt;\r\n    }\r\n}\r\n<\/pre>\n<h3 class=\"my_h\">(2) MainActivity.java<\/h3>\n<p>SubActivity\u3078\u306e\u5207\u308a\u66ff\u3048\u6642\u306b\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d7\u3051\u6e21\u3059\u305f\u3081\u306e MyParam\u30af\u30e9\u30b9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u5177\u4f53\u7684\u306b\u306f <span class=\"my_fc_deeppinkB\">putExtra<\/span> \u3067 Intent\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u57cb\u3081\u8fbc\u3080\u3002<\/p>\n<pre class=\"brush: java; highlight: [11,12]; title: ; notranslate\" title=\"\">\r\n    @Override\r\n    public boolean onTouchEvent(MotionEvent event) {\r\n        if(event.getAction() == MotionEvent.ACTION_UP) {\r\n            Intent intent = new Intent(getApplicationContext(), SubActivity.class);\r\n\r\n            \/\/ EditText\u304b\u3089\u5165\u529b\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u3002\r\n            EditText et = findViewById(R.id.et_textMain);\r\n            String txt = et.getText().toString();\r\n\r\n            \/\/ \u30af\u30e9\u30b9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3068\u3057\u3066\u57cb\u3081\u8fbc\u3080\u3002\r\n            MyParam myp = new MyParam(txt, 123);\r\n            intent.putExtra(&quot;myparam&quot;, myp);\r\n\r\n            \/\/ \u753b\u9762\u5207\u308a\u66ff\u3048\u3092\u5b9f\u884c\r\n            startActivity(intent);\r\n        }\r\n        return super.onTouchEvent(event);\r\n    }\r\n<\/pre>\n<h3 class=\"my_h\">(3) SubActivity.java<\/h3>\n<p>SubActivity\u306e\u751f\u6210\u6642\u306b\u3001\u53d7\u3051\u6e21\u3055\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d6\u308a\u51fa\u3057\u3001EditText\u306e\u521d\u671f\u5024\u3068\u3059\u308b\u3002<br \/>\n\u5177\u4f53\u7684\u306b\u306f <span class=\"my_fc_deeppinkB\">getSerializableExtra<\/span> \u3067 Intent\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d6\u308a\u51fa\u3059\u3002<\/p>\n<pre class=\"brush: java; highlight: [7,8]; title: ; notranslate\" title=\"\">\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_sub);\r\n\r\n        \/\/ \u5207\u308a\u66ff\u3048\u5143\u753b\u9762\u304b\u3089\u6e21\u3055\u308c\u305f\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u3002\r\n        Intent intent = getIntent();\r\n        MyParam myp = (MyParam)intent.getSerializableExtra(&quot;myparam&quot;);\r\n\r\n        \/\/ \u53d7\u3051\u53d6\u3063\u305f\u60c5\u5831\u3092 EditText\u306e\u521d\u671f\u5024\u306b\u4f7f\u7528\u3059\u308b\u3002\r\n        EditText et = findViewById(R.id.et_textSub);\r\n        et.setText(myp.getTxt());\r\n    }\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>0. \u95a2\u9023\u6295\u7a3f (39) \u30a2\u30d7\u30ea\u306e\u753b\u9762\u5207\u308a\u66ff\u3048\u3092\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u306e\u5909\u66f4\u3067\u5b9f\u73fe\u3059\u308b\u3002 (40) \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u5207\u308a\u66ff\u3048\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6e21\u3059\u3002 \u2190\u672c\u6295\u7a3f (41) \u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u7d42\u4e86\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u623b\u3059\u3002 1. \u3084\u308a\u305f\u3044\u3053\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/android\/blog40\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-780","post","type-post","status-publish","format-standard","hentry","category-androidstudio"],"views":849,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/comments?post=780"}],"version-history":[{"count":22,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/780\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/posts\/780\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/media?parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/categories?post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/android\/wp-json\/wp\/v2\/tags?post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}