Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Open Checklist"
- tools:layout_editor_absoluteX="136dp"
- tools:layout_editor_absoluteY="407dp" />
- </android.support.constraint.ConstraintLayout>
- ================================================================
- package com.example.kandydatpl;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- private Button btn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- btn = findViewById(R.id.button);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- openChecklist(v);
- }
- });
- }
- public void openChecklist(View view) {
- Intent intent = new Intent(this, TaskListActivity.class);
- startActivity(intent);
- }
- }
- ====================================================================================
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".TaskListActivity">
- <LinearLayout
- android:id="@+id/linearLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <EditText
- android:id="@+id/item_edit_text"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="4"
- android:hint="Enter Item" />
- <Button
- android:id="@+id/add_btn"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="Add" />
- </LinearLayout>
- <ListView
- android:id="@+id/items_list"
- android:layout_width="395dp"
- android:layout_height="667dp"
- android:layout_marginTop="8dp"
- android:layout_marginBottom="8dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/linearLayout"
- tools:layout_editor_absoluteX="8dp" />
- </android.support.constraint.ConstraintLayout>
- ==============================================================================
- package com.example.kandydatpl;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.Toast;
- import java.io.File;
- import java.util.ArrayList;
- public class TaskListActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
- private EditText itemET;
- private Button btn;
- private ListView itemsList;
- private ArrayList<String> items;
- private ArrayAdapter<String> adapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_task_list);
- itemET = findViewById(R.id.item_edit_text);
- btn = findViewById(R.id.add_btn);
- btn.setOnClickListener(this);
- itemsList = findViewById(R.id.items_list);
- items = FileHelper.readData(this);
- adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
- itemsList.setAdapter(adapter);
- itemsList.setOnItemClickListener(this);
- }
- public void onClickAdd(View view)
- {
- switch (view.getId())
- {
- case R.id.add_btn:
- String itemEntered = itemET.getText().toString();
- adapter.add(itemEntered);
- itemET.setText("");
- FileHelper.writeData(items, this);
- Toast.makeText(this, "Item Added!", Toast.LENGTH_SHORT).show();
- break;
- }
- }
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- items.remove(position);
- adapter.notifyDataSetChanged();
- FileHelper.writeData(items, this);
- Toast.makeText(this, "Delete", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onClick(View v) {
- onClickAdd(v);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement