https://github.com/sayed3li97/todoapp-android
Simple Android To-do app. One Activity that displays a list of data which is stored in an Array List. A Flotation Action Button (FAB) is used to show a dialog box with an input field for the user to add new items to his list. This project is part of a workshop titled "Introduction to Android" aimed to help beginners get into Android.
https://github.com/sayed3li97/todoapp-android
Last synced: about 1 year ago
JSON representation
Simple Android To-do app. One Activity that displays a list of data which is stored in an Array List. A Flotation Action Button (FAB) is used to show a dialog box with an input field for the user to add new items to his list. This project is part of a workshop titled "Introduction to Android" aimed to help beginners get into Android.
- Host: GitHub
- URL: https://github.com/sayed3li97/todoapp-android
- Owner: sayed3li97
- Created: 2019-01-28T19:34:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-10T11:00:13.000Z (over 4 years ago)
- Last Synced: 2023-10-06T11:41:46.556Z (over 2 years ago)
- Language: Java
- Homepage:
- Size: 318 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ToDoApp
Simple Android To-do app. One Activity displays a list of data that is stored in an Array List.
A Flotation Action Button (FAB) shows a dialog box with an input field for the user to add new items to his list.
This project is part of a workshop titled "Introduction to Android" to help beginners get into Android.
# Screenshots
# Step to re-create
1. Create a new project in Android Studio (Choose the Empty Activity)
2. [Dwnload this Image](app/src/main/res/drawable/plus.png) and insert it into the drawable folder inside your project
3. Navigate to app/res/layout/activity_main.xml
4. Open the "Text" view and replace the XML code with the below Code
The Code below will add to elements to the Layout:
1. ListView that will display all the data in a List
2. A FAB button
```
```
5. Open the java file for the main Activity by opening the MainActivity.java from the following path app/java/"The first folder"/MainActivity.java
6. Replace the Code in that file with the below Code ("Don't remove the first line starting with the package")
```
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
//Define an Array list to store all the data that will be displyed
ArrayList items = new ArrayList();
//Variable to store the dialog text input
private String m_Text = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Add data to the array
items.add("Milk");
items.add("Butter");
items.add("Yogurt");
items.add("Toothpaste");
items.add("Ice Cream");
//Define a listview
ListView listView1 = (ListView) findViewById(R.id.listView1);
//Define an array adapter
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, items);
//Connect the Listview to the adapter
listView1.setAdapter(adapter);
//Defining the Fab Button
FloatingActionButton fab = findViewById(R.id.fab);
//Add onclick listener to the Fab button that will trigger when the fab button is clicked
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Creating the dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Add to the list");
// Set up the input
final EditText input = new EditText(MainActivity.this);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT );
//Ading the Edit text to the dialog bo
builder.setView(input);
// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_Text = input.getText().toString();
items.add(m_Text);
}
});
//Set up the Cancel button
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
//To show the Dialog box
builder.show();
//To update the list View
adapter.notifyDataSetChanged();
}
});
}
}
```
Thank you!