Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8.  
  9. <TextView
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="Hello World!"
  13. app:layout_constraintBottom_toBottomOf="parent"
  14. app:layout_constraintLeft_toLeftOf="parent"
  15. app:layout_constraintRight_toRightOf="parent"
  16. app:layout_constraintTop_toTopOf="parent" />
  17.  
  18. <Button
  19. android:id="@+id/button"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:text="Open Checklist"
  23. tools:layout_editor_absoluteX="136dp"
  24. tools:layout_editor_absoluteY="407dp" />
  25.  
  26. </android.support.constraint.ConstraintLayout>
  27.  
  28.  
  29. ================================================================
  30. package com.example.kandydatpl;
  31.  
  32. import android.content.Intent;
  33. import android.support.v7.app.AppCompatActivity;
  34. import android.os.Bundle;
  35. import android.view.View;
  36. import android.widget.Button;
  37. import android.widget.Toast;
  38.  
  39. public class MainActivity extends AppCompatActivity {
  40.  
  41.  
  42. private Button btn;
  43.  
  44. @Override
  45. protected void onCreate(Bundle savedInstanceState) {
  46. super.onCreate(savedInstanceState);
  47. setContentView(R.layout.activity_main);
  48.  
  49. btn = findViewById(R.id.button);
  50. btn.setOnClickListener(new View.OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. openChecklist(v);
  54. }
  55. });
  56. }
  57.  
  58. public void openChecklist(View view) {
  59. Intent intent = new Intent(this, TaskListActivity.class);
  60. startActivity(intent);
  61. }
  62.  
  63. }
  64.  
  65.  
  66. ====================================================================================
  67.  
  68. <?xml version="1.0" encoding="utf-8"?>
  69. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  70. xmlns:app="http://schemas.android.com/apk/res-auto"
  71. xmlns:tools="http://schemas.android.com/tools"
  72. android:layout_width="match_parent"
  73. android:layout_height="match_parent"
  74. android:orientation="vertical"
  75. tools:context=".TaskListActivity">
  76.  
  77. <LinearLayout
  78. android:id="@+id/linearLayout"
  79. android:layout_width="match_parent"
  80. android:layout_height="wrap_content"
  81. android:orientation="horizontal">
  82.  
  83. <EditText
  84. android:id="@+id/item_edit_text"
  85. android:layout_width="0dp"
  86. android:layout_height="wrap_content"
  87. android:layout_weight="4"
  88. android:hint="Enter Item" />
  89.  
  90. <Button
  91. android:id="@+id/add_btn"
  92. android:layout_width="0dp"
  93. android:layout_height="wrap_content"
  94. android:layout_weight="1"
  95. android:text="Add" />
  96.  
  97. </LinearLayout>
  98.  
  99. <ListView
  100. android:id="@+id/items_list"
  101. android:layout_width="395dp"
  102. android:layout_height="667dp"
  103. android:layout_marginTop="8dp"
  104. android:layout_marginBottom="8dp"
  105. app:layout_constraintBottom_toBottomOf="parent"
  106. app:layout_constraintTop_toBottomOf="@+id/linearLayout"
  107. tools:layout_editor_absoluteX="8dp" />
  108.  
  109. </android.support.constraint.ConstraintLayout>
  110.  
  111. ==============================================================================
  112.  
  113. package com.example.kandydatpl;
  114.  
  115. import android.content.Intent;
  116. import android.support.v7.app.AppCompatActivity;
  117. import android.os.Bundle;
  118. import android.view.View;
  119. import android.widget.AdapterView;
  120. import android.widget.ArrayAdapter;
  121. import android.widget.Button;
  122. import android.widget.EditText;
  123. import android.widget.ListView;
  124. import android.widget.Toast;
  125.  
  126. import java.io.File;
  127. import java.util.ArrayList;
  128.  
  129. public class TaskListActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
  130.  
  131. private EditText itemET;
  132. private Button btn;
  133. private ListView itemsList;
  134. private ArrayList<String> items;
  135. private ArrayAdapter<String> adapter;
  136.  
  137. @Override
  138. protected void onCreate(Bundle savedInstanceState) {
  139. super.onCreate(savedInstanceState);
  140. setContentView(R.layout.activity_task_list);
  141.  
  142. itemET = findViewById(R.id.item_edit_text);
  143.  
  144. btn = findViewById(R.id.add_btn);
  145. btn.setOnClickListener(this);
  146.  
  147. itemsList = findViewById(R.id.items_list);
  148.  
  149. items = FileHelper.readData(this);
  150.  
  151. adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
  152. itemsList.setAdapter(adapter);
  153.  
  154. itemsList.setOnItemClickListener(this);
  155. }
  156.  
  157.  
  158. public void onClickAdd(View view)
  159. {
  160. switch (view.getId())
  161. {
  162. case R.id.add_btn:
  163. String itemEntered = itemET.getText().toString();
  164. adapter.add(itemEntered);
  165. itemET.setText("");
  166. FileHelper.writeData(items, this);
  167. Toast.makeText(this, "Item Added!", Toast.LENGTH_SHORT).show();
  168. break;
  169. }
  170. }
  171.  
  172. @Override
  173. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  174. items.remove(position);
  175. adapter.notifyDataSetChanged();
  176. FileHelper.writeData(items, this);
  177. Toast.makeText(this, "Delete", Toast.LENGTH_SHORT).show();
  178. }
  179.  
  180. @Override
  181. public void onClick(View v) {
  182. onClickAdd(v);
  183. }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement