{"id":12084,"date":"2015-05-13T09:59:46","date_gmt":"2015-05-13T00:59:46","guid":{"rendered":"http:\/\/35.247.82.29\/wpbl\/?p=12084"},"modified":"2021-08-12T01:58:45","modified_gmt":"2021-08-11T16:58:45","slug":"xml%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e4%bd%bf%e3%82%8f%e3%81%9a%e3%81%abfragment%e3%82%92%e7%94%9f%e6%88%90%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95%ef%bd%a5%cf%89%ef%bd%a5%ef%bd%80","status":"publish","type":"post","link":"https:\/\/mole-kingdom.com\/wpbl\/2015\/05\/13\/12084.html","title":{"rendered":"xml\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u308f\u305a\u306bFragment\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5(\u00b4\uff65\u03c9\uff65\uff40)\uff1f"},"content":{"rendered":"<p>xml\u3092\u4f7f\u308f\u305a\u306bFragment\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5\u3092\u3050\u3050\u3063\u3066\u3044\u3066\u3001\u30d2\u30c3\u30c8\u3057\u305f<br \/>\n<del datetime=\"2021-08-11T16:55:06+00:00\">android - How to programmatically create the layout for a Fragment?<\/del><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/5159982\/how-do-i-add-a-fragment-to-an-activity-with-a-programmatically-created-content-v\" target=\"_blank\" rel=\"noopener\">android - How do I add a Fragment to an Activity with a programmatically created content view<\/a><br \/>\n\u3092\u53c2\u8003\u306b\u30b3\u30fc\u30c9\u3092\u3067\u3063\u3061\u4e0a\u3052\u305f\u304c\u3001\u679c\u305f\u3057\u3066\u3053\u308c\u3067\u6b63\u3057\u3044\u306e\u304b\u3069\u3046\u304b\u3088\u304f\u308f\u304b\u3089\u306a\u3044\uff57<\/p>\n<p>\u305d\u3082\u305d\u3082\u306a\u3093\u3067\u305d\u3093\u306a\u3053\u3068\u3092\u3057\u3088\u3046\u3057\u305f\u306e\u304b\u3068\u3044\u3046\u3068\u3001\u524d\u306e\u30a8\u30f3\u30c8\u30ea\u3092\u78ba\u8a8d\u3057\u3066\u3044\u308b\u6642\u306b<br \/>\nLongClick\u3092\u62fe\u3048\u306a\u304f\u306a\u3063\u305f\u6642\u306b\u300c\u524d\u306b\u8a66\u3057\u305f\u30b3\u30fc\u30c9\u306fListFragment\u3060\u3063\u305f\u304b\u3089\u3001\u305d\u308c\u3068<br \/>\n\u4e00\u7dd2\u306b\u3057\u306a\u3044\u3068\u518d\u73fe\u3067\u304d\u306a\u3044\u306e\u304b\u2026( \uff1b\uff65\u00b4\u03c9\uff65\uff40)\uff7a\uff9e\uff78\uff98\uff6f\uff1f\u300d\u3068\u3044\u3046\u52d8\u9055\u3044\u3092\u3057\u3066\u3001\u304b\u3064\u3001<br \/>\n\u300c\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u30ef\u30f3\u30b9\u30c8\u30c3\u30d7\u306a\u3089\u306c\u30ef\u30f3\u30b3\u30d4\u30da\u3067\u5b8c\u7d50\u3059\u3079\u304d(\uff40\u30fb\u03c9\u30fb\u00b4)\u300d\u3068\u3044\u3046<br \/>\n\u8b0e\u306e\u601d\u60f3\u304b\u3089\u3001xml\u30d5\u30a1\u30a4\u30eb\u306b\u3088\u308b\u30ec\u30a4\u30a2\u30a6\u30c8\u6307\u5b9a\u3092\u7121\u3057\u306b\u3057\u305f\u3044\u3068\u601d\u3063\u305f\u304b\u3089(\uff89\u2200`)<\/p>\n<p>\u4e00\u5fdc\u3053\u308c\u3067\u51fa\u6765\u3066\u308b\u307f\u305f\u3044\u3060\u3051\u308c\u3069\u3082\u3001\u5b9f\u969b\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e00\u90e8\u3068\u3057\u3066\u4f7f\u3046\u306b\u306f<br \/>\n\u3082\u3063\u3068\u4f55\u304b\u3092\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u304c\u3001\u305d\u306e\u8fba\u306f\u3088\u304f\u308f\u304b\u3089\u306a\u3044\uff57<\/p>\n<p>\u53d6\u308a\u6562\u3048\u305a\u30ef\u30f3\u30b3\u30d4\u30da\u3067\u8a66\u305b\u308bFragment\u3092\u4f7f\u7528\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u308b\u306e\u306b\u306f<br \/>\n\u5229\u7528\u51fa\u6765\u308b\u306e\u3067\u3001\u3053\u308c\u306f\u3053\u308c\u3067\u3044\u3044\u304b\u306a\u3002<\/p>\n<p>\u306a\u305c\u304bLongClick\u3067Toast\u304c\u8868\u793a\u51fa\u6765\u306a\u3044\u306e\u306f\u8b0e(\u00b4\uff65\u03c9\uff65\uff40)<br \/>\nLog.d\u306b\u306f\u51fa\u529b\u3055\u308c\u3066\u3044\u308b\u306e\u306b\u3002\u307e\u3042\u30bf\u30c3\u30c1\u30a4\u30d9\u30f3\u30c8\u95a2\u9023\u306f\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u306e<br \/>\n\u672c\u8cea\u3068\u306f\u5168\u304f\u95a2\u4fc2\u306a\u3044\u306e\u3060\u3051\u308c\u3069\uff57<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport android.app.Activity;\r\nimport android.app.Fragment;\r\nimport android.app.FragmentTransaction;\r\nimport android.graphics.Color;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\nimport android.view.GestureDetector;\r\nimport android.view.GestureDetector.SimpleOnGestureListener;\r\nimport android.view.LayoutInflater;\r\nimport android.view.MotionEvent;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.ViewGroup.LayoutParams;\r\nimport android.widget.AdapterView;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.LinearLayout;\r\nimport android.widget.ListView;\r\nimport android.widget.Toast;\r\n\r\npublic class MainActivity extends Activity {\r\n\r\n\tprivate GestureDetector mGestureDetector;\r\n\tprivate View.OnTouchListener mGestureListener;\r\n\tprivate static final int CONTENT_VIEW_ID = 10101010;\r\n\tprivate static final String&#x5B;] CONFECTIONERY = {\r\n\t\t&quot;Apple Pie&quot;, &quot;Banana Bread&quot;, &quot;Cupcake&quot;, &quot;Donut&quot;, &quot;Eclair&quot;, &quot;Froyo&quot;,\r\n\t\t&quot;Gingerbread&quot;, &quot;Honeycomb&quot;, &quot;Ice Cream Sandwich&quot;, &quot;Jelly Bean&quot;,\r\n\t\t&quot;KitKat&quot;, &quot;Lollipop&quot;\r\n\t};\r\n\r\n\t@Override\r\n\tprotected void onCreate(Bundle savedInstanceState) {\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\r\n\t\tLinearLayout layout=new LinearLayout(this);\r\n\t\tlayout.setBackgroundColor(Color.WHITE);\r\n\t\tlayout.setOrientation(LinearLayout.VERTICAL);\r\n\t\tlayout.setId(CONTENT_VIEW_ID);\r\n\r\n\t\tsetContentView(layout, new LayoutParams(\r\n\t\t\t\tLayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));\r\n\r\n\t\tBundle bundle = new Bundle();\r\n\t\tbundle.putStringArray(&quot;confectionery&quot;, CONFECTIONERY);\r\n\r\n\t\tif (savedInstanceState == null) {\r\n\t\t\tFragment newFragment = new MyFragment();\r\n\t\t\tFragmentTransaction ft = getFragmentManager().beginTransaction();\r\n\t\t\tft.add(CONTENT_VIEW_ID, newFragment).commit();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void myOnItemClick(int position) {\r\n\t\tLog.d(&quot;myOnItemClick&quot;, &quot;itemClick: &quot; + position);\r\n\t\tToast.makeText(MainActivity.this, &quot;myOnItemClick itemClick&quot; + position, Toast.LENGTH_LONG).show();\r\n\t}\r\n\r\n\tpublic class MyFragment extends Fragment {\r\n\r\n\t\tpublic MyFragment() {}\r\n\r\n\t\tView rootView;\r\n\t\tListView listView;\r\n\t\t@Override\r\n\t\tpublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\r\n\t\t\tLinearLayout layout=new LinearLayout(getActivity());\r\n\t\t\tLog.d(&quot;MyFragment&quot;, &quot;onCreateView&quot;);\r\n\t\t\tlayout.setOrientation(LinearLayout.VERTICAL);\r\n\r\n\t\t\tlistView = new ListView(getActivity());\r\n\r\n\t\t\tlistView.setLayoutParams(new LinearLayout.LayoutParams(\r\n\t\t\t\t\tLayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));\r\n\t\t\tlistView.setAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1,\r\n\t\t\t\t\tCONFECTIONERY));\r\n\r\n\t\t\tlayout.addView(listView);\r\n\r\n\t\t\trootView = layout;\r\n\t\t\trootView.setBackgroundColor(Color.WHITE);\r\n\t\t\treturn rootView;\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic void onActivityCreated(Bundle savedInstanceState) {\r\n\t\t\tsuper.onActivityCreated(savedInstanceState);\r\n\r\n\t\t\tmGestureDetector = new GestureDetector(getActivity(),new MyGestureDetector());\r\n\t\t\tmGestureListener = new View.OnTouchListener() {\r\n\t\t\t\t@Override\r\n\t\t\t\tpublic boolean onTouch(View v, MotionEvent event) {\r\n\t\t\t\t\treturn mGestureDetector.onTouchEvent(event);\r\n\t\t\t\t}\r\n\t\t\t};\r\n\r\n\t\t\tlistView.setOnTouchListener(mGestureListener);\r\n\t\t\tlistView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {\r\n\t\t\t\t@Override\r\n\t\t\t\tpublic boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {\r\n\t\t\t\t\tLog.d(&quot;onItemLongClick&quot;, &quot;LongClick&quot;);\r\n\t\t\t\t\tToast.makeText(MainActivity.this, &quot;onItemLongClick LongClick&quot;, Toast.LENGTH_LONG).show();\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tclass MyGestureDetector extends SimpleOnGestureListener {\r\n\t\t\tprivate static final int SWIPE_MIN_DISTANCE = 120;\r\n\t\t\tprivate static final int SWIPE_MAX_OFF_PATH = 250;\r\n\t\t\tprivate static final int SWIPE_THRESHOLD_VELOCITY = 200;\r\n\r\n\t\t\t@Override\r\n\t\t\tpublic boolean onSingleTapUp(MotionEvent e) {\r\n\t\t\t\tint pos = listView.pointToPosition((int)e.getX(), (int)e.getY());\r\n\t\t\t\tmyOnItemClick(pos);\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\r\n\t\t\t@Override\r\n\t\t\tpublic boolean onFling(MotionEvent e1, MotionEvent e2,\r\n\t\t\t\t\tfloat velocityX, float velocityY) {\r\n\t\t\t\tif (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) {\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tboolean isDoCancel = false;\r\n\r\n\t\t\t\tif (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {\r\n\t\t\t\t\tLog.d(&quot;onFling&quot;, &quot;FlingLeft&quot;);\r\n\t\t\t\t\tToast.makeText(MainActivity.this, &quot;onFling FlingLeft&quot;, Toast.LENGTH_LONG).show();\r\n\r\n\t\t\t\t\tisDoCancel = true;\r\n\r\n\t\t\t\t} else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {\r\n\t\t\t\t\tLog.d(&quot;onFling&quot;, &quot;FlingRight&quot;);\r\n\t\t\t\t\tToast.makeText(MainActivity.this, &quot;onFling FlingRight&quot;, Toast.LENGTH_LONG).show();\r\n\r\n\t\t\t\t\tisDoCancel = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif(isDoCancel){\r\n\t\t\t\t\tMotionEvent cancelEvent = MotionEvent.obtain(e2);\r\n\t\t\t\t\tcancelEvent.setAction(MotionEvent.ACTION_UP);\r\n\t\t\t\t\tlistView.onTouchEvent(cancelEvent);\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}else{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>xml\u3092\u4f7f\u308f\u305a\u306bFragment\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5\u3092\u3050\u3050\u3063\u3066\u3044\u3066\u3001\u30d2\u30c3\u30c8\u3057\u305f android - How to programmatically create the layout for a Fragment? andro...  <a class=\"excerpt-read-more\" href=\"https:\/\/mole-kingdom.com\/wpbl\/2015\/05\/13\/12084.html\" title=\"Read xml\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u308f\u305a\u306bFragment\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5(\u00b4\uff65\u03c9\uff65\uff40)\uff1f\">\u3082\u3063\u3068\u8aad\u3080 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18,17],"tags":[],"class_list":["post-12084","post","type-post","status-publish","format-standard","hentry","category-android","category-programming"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2pLuj-38U","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":24934,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/12\/24934.html","url_meta":{"origin":12084,"position":0},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(3)","author":"moleking","date":"2021\u5e747\u670812\u65e5","format":false,"excerpt":"Android Kotlin Fundamentals 02.4:Data binding basi\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24927,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/06\/24927.html","url_meta":{"origin":12084,"position":1},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(1)","author":"moleking","date":"2021\u5e747\u67086\u65e5","format":false,"excerpt":"Android Kotlin \u306e\u57fa\u790e\u306e\u305f\u3081\u306e Codelab \u3068\u8a00\u3044\u3064\u3064\u3001\u307e\u3060\u9014\u4e2d(\uff89\u2200`) \u307e\u3060L\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24858,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/23\/24858.html","url_meta":{"origin":12084,"position":2},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(\u7d42)","author":"moleking","date":"2021\u5e746\u670823\u65e5","format":false,"excerpt":"\u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u9593\u306e\u5171\u6709 ViewModel 4. \u5171\u6709 ViewModel \u3092\u4f5c\u6210\u3059\u308b OrderVi\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24848,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/17\/24848.html","url_meta":{"origin":12084,"position":3},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(2)","author":"moleking","date":"2021\u5e746\u670817\u65e5","format":false,"excerpt":"Layouts Kotlin\u306e\u30af\u30e9\u30b9\u3068\u7d99\u627f 2. \u30af\u30e9\u30b9\u968e\u5c64\u3068\u306f \u4e00\u5fdc\u3001\"\u8c46\u985e\"\u306e\u3068\u3053\u308d\u306e\u30ea\u30f3\u30af\u304ch\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24935,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/15\/24935.html","url_meta":{"origin":12084,"position":4},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(4)","author":"moleking","date":"2021\u5e747\u670815\u65e5","format":false,"excerpt":"Android Kotlin Fundamentals: Lifecycles and loggin\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24932,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/09\/24932.html","url_meta":{"origin":12084,"position":5},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(2)","author":"moleking","date":"2021\u5e747\u67089\u65e5","format":false,"excerpt":"Android Kotlin Fundamentals: Add user interactivit\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/12084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/comments?post=12084"}],"version-history":[{"count":4,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/12084\/revisions"}],"predecessor-version":[{"id":25758,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/12084\/revisions\/25758"}],"wp:attachment":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/media?parent=12084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/categories?post=12084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/tags?post=12084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}