-
Notifications
You must be signed in to change notification settings - Fork 6
/
ToDOlist.java
32 lines (23 loc) · 1.01 KB
/
ToDOlist.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class ToDOlist {
}
/////////////////////////// Todo List
editText=findViewById(R.id.teditText);listView=findViewById(R.id.listview);button=(Button)findViewById(R.id.button);
ArrayList<String> listOfItem = new ArrayList<>();
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,
listOfItem);listView.setAdapter(adapter);
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
String item = editText.getText().toString();
listOfItem.add(item);
adapter.notifyDataSetChanged();
}
}
//Remove item from list
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
listOfItem.remove(item);
adapter.notifyDataSetChanged();
}
});