Guest User

Untitled

a guest
Dec 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. public class MainMenu extends AppCompatActivity {
  2.  
  3. ListView listView;
  4. EditText editTextView;
  5. ArrayList<Lesson> ItemModelList;
  6. CustomAdapter customAdapter;
  7. Button BLogout;
  8.  
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_mainmenu);
  14.  
  15.  
  16. final TextView welcomeMessage = (TextView) findViewById(R.id.tvWelcome);
  17. final Button BLogout = (Button) findViewById(R.id.BLogout);
  18.  
  19. Intent intent = getIntent();
  20. String username = intent.getStringExtra("username");
  21.  
  22.  
  23. String message = username + " Welcome";
  24. welcomeMessage.setText(message);
  25.  
  26.  
  27. BLogout.setOnClickListener(new View.OnClickListener() {
  28. @Override
  29. public void onClick(View view) {
  30. Intent registerIntent = new Intent(MainMenu.this, Login.class);
  31. MainMenu.this.startActivity(registerIntent);
  32. }
  33. });
  34.  
  35. listView = (ListView) findViewById(R.id.listview);
  36. editTextView = (EditText) findViewById(R.id.editTextView);
  37. ItemModelList = new ArrayList<Lesson>();
  38. customAdapter = new CustomAdapter(getApplicationContext(), ItemModelList);
  39. listView.setEmptyView(findViewById(R.id.empty));
  40. listView.setAdapter(customAdapter);
  41. }
  42.  
  43. @SuppressLint("NewApi")
  44. public void addValue(View v) {
  45. String name = editTextView.getText().toString();
  46. if (name.isEmpty()) {
  47. Toast.makeText(getApplicationContext(), "Plz enter Values",
  48. Toast.LENGTH_SHORT).show();
  49. } else {
  50. Lesson md = new Lesson(name);
  51. ItemModelList.add(md);
  52. customAdapter.notifyDataSetChanged();
  53. editTextView.setText("");
  54.  
  55.  
  56. }
  57.  
  58. }}
  59.  
  60. ublic class CustomAdapter extends BaseAdapter {
  61. Context context;
  62. ArrayList<Lesson> itemLessonList;
  63. public CustomAdapter(Context context, ArrayList<Lesson> lessonList) {
  64. this.context = context;
  65. this.itemLessonList = lessonList;
  66. }
  67. @Override
  68. public int getCount() {
  69. return itemLessonList.size();
  70. }
  71. @Override
  72. public Object getItem(int position) {
  73. return itemLessonList.get(position);
  74. }
  75. @Override
  76. public long getItemId(int position) {
  77. return position;
  78. }
  79. @Override
  80. public View getView(final int position, View convertView, ViewGroup parent) {
  81. convertView = null;
  82. if (convertView == null) {
  83. LayoutInflater mInflater = (LayoutInflater) context
  84. .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  85. convertView = mInflater.inflate(R.layout.item, null);
  86. TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
  87. ImageView imgRemove = (ImageView) convertView.findViewById(R.id.BDelete);
  88. Lesson m = itemLessonList.get(position);
  89. tvName.setText(m.getName());
  90. // click listener for remove button
  91. imgRemove.setOnClickListener(new View.OnClickListener() {
  92. @Override
  93. public void onClick(View v) {
  94. itemLessonList.remove(position);
  95. notifyDataSetChanged();
  96. }
  97. });
  98. }
  99. return convertView;
  100. }}
  101.  
  102. public class Lesson {
  103. String name;
  104. public Lesson(String name) {
  105. this.name = name;
  106. }
  107.  
  108. public String getName() {
  109. return name;
  110. }}
  111.  
  112. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  113. xmlns:tools="http://schemas.android.com/tools"
  114. android:layout_width="match_parent"
  115. android:layout_height="match_parent"
  116. android:background="@drawable/gradient">
  117.  
  118. <TextView
  119. android:id="@+id/textView"
  120. android:layout_width="wrap_content"
  121. android:layout_height="35dp"
  122. android:layout_alignParentStart="true"
  123. android:layout_alignParentTop="true"
  124. android:gravity="left"
  125. android:text="Lesson Board"
  126. android:textColor="@android:color/holo_blue_dark"
  127. android:textSize="27sp" />
  128.  
  129. <Button
  130. android:id="@+id/BLogout"
  131. android:layout_width="wrap_content"
  132. android:layout_height="35dp"
  133. android:layout_alignParentEnd="true"
  134. android:layout_alignParentTop="true"
  135. android:text="Logout"
  136. android:background="@android:color/holo_blue_dark"/>
  137.  
  138. <TextView
  139. android:id="@+id/tvWelcome"
  140. android:layout_width="wrap_content"
  141. android:layout_height="wrap_content"
  142. android:layout_below="@+id/textView"
  143. android:layout_centerHorizontal="true"
  144. android:layout_marginTop="22dp"
  145. android:text="hello world"
  146. android:textColor="@android:color/holo_blue_dark"
  147. android:textAppearance="?android:attr/textAppearanceLarge" />
  148.  
  149. <LinearLayout
  150. android:layout_width="match_parent"
  151. android:layout_height="match_parent"
  152. android:layout_alignParentEnd="true"
  153. android:layout_below="@+id/tvWelcome"
  154. android:orientation="vertical">
  155. <LinearLayout
  156. android:layout_width="match_parent"
  157. android:layout_height="wrap_content"
  158. android:orientation="horizontal" >
  159. <EditText
  160. android:id="@+id/editTextView"
  161. android:layout_width="match_parent"
  162. android:layout_height="wrap_content"
  163. android:layout_weight="1"
  164. android:hint="Add lesson"
  165. android:textColor="@android:color/holo_blue_dark"
  166. />
  167. <ImageView
  168. android:id="@+id/imgViewAdd"
  169. android:layout_width="wrap_content"
  170. android:layout_height="wrap_content"
  171. android:onClick="addValue"
  172. android:background="@android:drawable/ic_input_add"
  173. />
  174. </LinearLayout>
  175. <ListView
  176. android:id="@+id/listview"
  177. android:layout_width="match_parent"
  178. android:layout_height="match_parent"
  179. android:layout_weight="1"
  180. android:dividerHeight="2dp"
  181. android:textColor="@android:color/holo_blue_dark">
  182. </ListView>
  183. </LinearLayout>
  184.  
  185. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  186. android:layout_width="match_parent"
  187. android:layout_height="match_parent"
  188. android:orientation="horizontal" >
  189. <TextView
  190. android:id="@+id/tvName"
  191. android:layout_width="match_parent"
  192. android:layout_height="wrap_content"
  193. android:layout_weight="1"
  194. android:gravity="left"
  195. android:padding="8dp"
  196. android:textColor="#000000"
  197. android:textSize="18sp" />
  198. <ImageView
  199. android:id="@+id/BDelete"
  200. android:layout_width="wrap_content"
  201. android:layout_height="wrap_content"
  202. android:focusable="false"
  203. android:background="@android:drawable/ic_delete" />
Add Comment
Please, Sign In to add comment