Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My daily tasks #726

Open
Heker678 opened this issue Dec 5, 2024 · 0 comments
Open

My daily tasks #726

Heker678 opened this issue Dec 5, 2024 · 0 comments

Comments

@Heker678
Copy link

Heker678 commented Dec 5, 2024

package com.example.todolist;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
private ArrayList taskList;
private ArrayAdapter adapter;

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

    // عناصر الشاشة
    ListView listView = findViewById(R.id.task_list);
    EditText inputTask = findViewById(R.id.input_task);
    Button addButton = findViewById(R.id.add_button);

    // إعداد قائمة المهام
    taskList = new ArrayList<>();
    adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskList);
    listView.setAdapter(adapter);

    // زر إضافة مهمة
    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String task = inputTask.getText().toString().trim();
            if (!task.isEmpty()) {
                taskList.add(task);
                adapter.notifyDataSetChanged();
                inputTask.setText(""); // إفراغ الحقل
            }
        }
    });

    // حذف مهمة عند الضغط عليها
    listView.setOnItemClickListener((parent, view, position, id) -> {
        taskList.remove(position);
        adapter.notifyDataSetChanged();
    });
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@Heker678 and others