Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private EditText inputEditText;
    private TextView outputTextView;
    private Button addButton;
    private ArrayList<String> tasksList;
    private String tasks = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        inputEditText = findViewById(R.id.inputEditText);
        outputTextView = findViewById(R.id.outputTextView);
        addButton = findViewById(R.id.addButton);
        tasksList = new ArrayList<>();

        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String newTask = inputEditText.getText().toString();
                if (!newTask.isEmpty()) {
                    tasksList.add(newTask);
                    tasks += "\n- " + newTask;
                    outputTextView.setText("Tasks for today:" + tasks);
                    inputEditText.getText().clear();
                }
            }
        });
    }
}