Guest User

Untitled

a guest
Jun 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. @Override
  2. public boolean onCreateOptionsMenu(Menu menu) {
  3. return super.onCreateOptionsMenu(menu); // false by default. so goes to fragment
  4. // If return true, than stay in the activity
  5. }
  6.  
  7. @Override
  8. public boolean onOptionsItemSelected(MenuItem item) {
  9. Toast.makeText(this, "onOptionsItemSelected", Toast.LENGTH_SHORT).show();
  10. switch(item.getItemId())
  11. {
  12. default:
  13. return super.onOptionsItemSelected(item);
  14. // false by default. so goes to fragment
  15. // If returns true stays in activity.
  16. }
  17. }
  18.  
  19. @Override
  20. public void onCreate(@Nullable Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setHasOptionsMenu(true);((AppCompatActivity)activity).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  23. }
  24.  
  25.  
  26.  
  27. @Override
  28. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  29. inflater.inflate(R.menu.menu_edit_mode,menu);
  30. setHasOptionsMenu(true);
  31. super.onCreateOptionsMenu(menu, inflater);
  32. }
  33.  
  34. @Override
  35. public boolean onOptionsItemSelected(MenuItem item) {
  36. Toast.makeText(activity,"onOptionItemSelected", Toast.LENGTH_SHORT).show(); // Not Invoked!!!
  37. if (!isDataInitialized()) return true;
  38. switch (item.getItemId()) {
  39.  
  40. case R.id.item_share: // Share Icon
  41. callUsernamesDialog();
  42. return true;
  43.  
  44.  
  45. case android.R.id.home: // Back pressing
  46. ( (ActivityProfile)activity).onBackPressed();
  47. return true;
  48.  
  49. default:
  50. return super.onOptionsItemSelected(item);
  51. }
  52.  
  53. }
  54.  
  55. <?xml version="1.0" encoding="utf-8"?>
  56.  
  57. <ScrollView android:layout_width="match_parent"
  58. android:layout_height="match_parent"
  59. xmlns:android="http://schemas.android.com/apk/res/android">
  60.  
  61. <LinearLayout
  62. xmlns:android="http://schemas.android.com/apk/res/android"
  63. xmlns:app="http://schemas.android.com/apk/res-auto"
  64. xmlns:tools="http://schemas.android.com/tools"
  65. android:layout_width="match_parent"
  66. android:layout_height="wrap_content"
  67. android:id="@+id/fragment_edit_data_layout"
  68. tools:context=".UserStuff.EditData.FragmentEditData"
  69. android:orientation="vertical"
  70. >
  71. <TextView
  72. android:layout_width="match_parent"
  73. android:layout_height="wrap_content"
  74. android:layout_marginTop="55dp"
  75. android:fontFamily="cursive"
  76. android:lineSpacingExtra="10sp"
  77. android:text="@string/edit_data"
  78. android:textAlignment="center"
  79. android:textAllCaps="false"
  80. android:textAppearance="@style/TextAppearance.AppCompat.Button"
  81. android:textColor="@color/colorPrimary"
  82. android:textSize="60sp"
  83. android:textStyle="bold"
  84. android:typeface="serif" />
  85.  
  86. <EditText
  87. android:id="@+id/et_title"
  88. style="@android:style/Widget.AutoCompleteTextView"
  89. android:layout_width="match_parent"
  90. android:layout_height="100dp"
  91. android:fontFamily="serif"
  92. android:hint="@string/title"
  93. android:inputType="textEmailAddress"
  94. android:textAppearance="@style/TextAppearance.AppCompat.Caption"
  95. android:textColor="@android:color/background_dark"
  96. android:textSize="18sp" />
  97.  
  98. <LinearLayout
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:orientation="horizontal"
  102. xmlns:android="http://schemas.android.com/apk/res/android"
  103. xmlns:app="http://schemas.android.com/apk/res-auto"
  104. xmlns:tools="http://schemas.android.com/tools"
  105. >
  106. <TextView
  107. android:layout_width="0dp"
  108. android:layout_height="wrap_content"
  109. android:layout_weight="1"
  110. android:layout_margin="8dp"
  111. android:text="@string/folder_category"
  112. />
  113. <android.support.v7.widget.AppCompatButton
  114. android:layout_width="0dp"
  115. android:layout_height="wrap_content"
  116. android:layout_weight="1"
  117. android:layout_marginLeft="@dimen/standard_21"
  118. android:layout_gravity="center"
  119. android:id="@+id/btn_category"
  120. android:text="@string/untitled"
  121. android:textSize="14sp"
  122. />
  123. <android.support.v7.widget.AppCompatButton
  124. android:layout_margin="8dp"
  125. android:layout_width="0dp"
  126. android:layout_height="wrap_content"
  127. android:layout_weight="1"
  128. android:textSize="14sp"
  129. android:text="@string/refresh"
  130. android:id="@+id/btn_refresh"
  131. />
  132. </LinearLayout>
  133. <EditText
  134. android:id="@+id/et_description"
  135. style="@android:style/Widget.AutoCompleteTextView"
  136. android:layout_width="match_parent"
  137. android:layout_height="100dp"
  138. android:fontFamily="serif"
  139. android:hint="@string/description"
  140. android:inputType="textEmailAddress"
  141. android:layout_margin="8dp"
  142. android:textAppearance="@style/TextAppearance.AppCompat.Caption"
  143. android:textColor="@android:color/background_dark"
  144. android:textSize="18sp" />
  145.  
  146. <android.support.v7.widget.AppCompatButton
  147. android:id="@+id/btn_edit_data"
  148. android:layout_width="match_parent"
  149. android:layout_height="wrap_content"
  150. android:backgroundTint="@color/colorPrimary"
  151. android:text="@string/tap_to_edit"
  152. android:textAlignment="center"
  153. android:textAllCaps="false"
  154. android:textColor="@color/cardview_light_background"
  155. android:textSize="24sp"/>
  156.  
  157. </LinearLayout>
  158.  
  159.  
  160. </ScrollView>
  161.  
  162. @Override
  163. public boolean onCreateOptionsMenu(Menu menu) {
  164. // Inflate the menu; this adds items to the action bar if it is present.
  165. getMenuInflater().inflate(R.menu.menu_edit_mode, menu);
  166. return true;
  167. }
  168.  
  169. @Override
  170. public boolean onOptionsItemSelected(MenuItem item) {
  171. int id = item.getItemId();
  172. switch (id){
  173. case R.id.item1:
  174. Toast.makeText(getApplicationContext(),"Item 1 Selected",Toast.LENGTH_LONG).show();
  175. return true;
  176. case R.id.item2:
  177. Toast.makeText(getApplicationContext(),"Item 2 Selected",Toast.LENGTH_LONG).show();
  178. return true;
  179. case R.id.item3:
  180. Toast.makeText(getApplicationContext(),"Item 3 Selected",Toast.LENGTH_LONG).show();
  181. return true;
  182. default:
  183. return super.onOptionsItemSelected(item);
  184. }
  185. }
  186.  
  187. @Override
  188. public boolean onCreateOptionsMenu(Menu menu) {
  189. MenuInflater inflater = getSupportMenuInflater();
  190. inflater.inflate(R.menu.main, menu);
  191. return true;
  192. }
  193.  
  194. @Override
  195. public boolean onOptionsItemSelected(MenuItem item) {
  196. switch (item.getItemId()) {
  197.  
  198. case R.id.activity_menu_item:
  199.  
  200. // Do Activity menu item stuff here
  201. return true;
  202.  
  203. case R.id.fragment_menu_item:
  204.  
  205. // Not implemented here
  206. return false;
  207. default:
  208. break;
  209. }
  210.  
  211. return false;
  212. }
  213.  
  214. @Override
  215. public boolean onCreateOptionsMenu(Menu menu) {
  216. MenuInflater inflater = getSupportMenuInflater();
  217. inflater.inflate(R.menu.main, menu);
  218. return true;
  219. }
  220. public void onCreate(Bundle savedInstanceState) {
  221. super.onCreate(savedInstanceState);
  222. setHasOptionsMenu(true);
  223. }
  224. @Override
  225. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  226. // Do something that differs the Activity's menu here
  227. super.onCreateOptionsMenu(menu, inflater);
  228. }
  229. @Override
  230. public boolean onOptionsItemSelected(MenuItem item) {
  231. switch (item.getItemId()) {
  232. case R.id.activity_menu_item:
  233. // Not implemented here
  234. return false;
  235. case R.id.fragment_menu_item:
  236. // Do Fragment menu item stuff here
  237. return true;
  238.  
  239. default:
  240. break;
  241. }
  242.  
  243. return false;
  244. }
Add Comment
Please, Sign In to add comment