Yes, in this article we did two things,
1. Adding Items to ListView
2. Register ListView to event(OnItemClickListner) to find which item is clicked.
Adding Items to ListView
In Add(onclick) adding items to Listview at runtime using ArrayList, ArrayAdapter of string type.
ArrayAdapter will take String[] as a parameter as a source. so i taken arraylist(al). arraylist can take string item.
String item=edt.getText().toString().trim();
al.add(item); then adapter will be updated automatically using predefined event
adapter.notifyDataSetChanged(); at onCreate method it taken al as input/source.
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,al);
Register OnItemClickListener
import android.widget.AdapterView.OnItemClickListener;
MainActivity implement OnItemClickListerner also. which fires whenever an item is clicked on ListView.
this event has 4 parameters.
onItemClick(AdapterView<?> parent, View view, int position,long id);
parent : is Listview,Gridview,spinner,...ect who currently binding Adapterview data.
as well we can check (Listview1, Listview2..also)
view : view with in the AdapterView.
position : item position in the adapterview.
args3 : the Row id of the item was clicked.
1. Adding Items to ListView
2. Register ListView to event(OnItemClickListner) to find which item is clicked.
Adding Items to ListView
In Add(onclick) adding items to Listview at runtime using ArrayList, ArrayAdapter of string type.
ArrayAdapter will take String[] as a parameter as a source. so i taken arraylist(al). arraylist can take string item.
String item=edt.getText().toString().trim();
al.add(item); then adapter will be updated automatically using predefined event
adapter.notifyDataSetChanged(); at onCreate method it taken al as input/source.
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,al);
Register OnItemClickListener
import android.widget.AdapterView.OnItemClickListener;
MainActivity implement OnItemClickListerner also. which fires whenever an item is clicked on ListView.
this event has 4 parameters.
onItemClick(AdapterView<?> parent, View view, int position,long id);
parent : is Listview,Gridview,spinner,...ect who currently binding Adapterview data.
as well we can check (Listview1, Listview2..also)
view : view with in the AdapterView.
position : item position in the adapterview.
args3 : the Row id of the item was clicked.