I want to delete an element from the list when a button x is clicked on the layout of a list element. Here is my java code, onNext() is working for adding an element to the list . but the onDelete isnt working.The textView4 element has numbers starting from 1 to n when new elements are added
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list2);
arrayList = new ArrayList<String>();
arrayList.add("1");
adapter2 = new ArrayAdapter<String>(this, R.layout.list2_layout, R.id.textView4, arrayList);
ListView myList2 = (ListView)
findViewById(R.id.listView2);
myList2.setAdapter(adapter2);
}
public void onNextItem(View v)
{
counter++;
String str=Integer.toString(counter);
arrayList.add(str);
adapter2.notifyDataSetChanged();
}
public void onDeleteItem(View v2)
{
arrayList.remove(R.id.textView4);
adapter2.notifyDataSetChanged();
}