Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:19:20+00:00 2026-06-15T02:19:20+00:00

I am unable to delete an item using delete button in each row of

  • 0

I am unable to delete an item using delete button in each row of the ListView. I don’t know how to get the current position of the button click of the Listview item. Can you help me out how to solve this problem .
All I want to do is that when I click delete button that particular row gets deleted.

Following are the main activity code and xml code

My Xml code for expandable listview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:slide="http://schemas.android.com/apk/res/com.example.test_expendable"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".Create_Team_Form" >

<RelativeLayout
    android:id="@+id/item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Hello World"
        android:textSize="20dip" />

    <Button
        android:id="@+id/expandable_toggle_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/Team_More" />
</RelativeLayout>

<LinearLayout
    android:id="@+id/expandable"
    android:layout_width="fill_parent"
    android:layout_height="40dip"
    android:background="#000000"
    android:orientation="horizontal" >


    <Button
        android:id="@+id/btn_Del"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:onClick="Team_Delete"
        android:text="@string/Team_Del"
        android:textSize="12dip" />


    <Button
        android:id="@+id/btn_Details"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:onClick="Team_Details"
        android:text="@string/Team_Detail"
        android:textSize="12dip" />

   </LinearLayout>

 </LinearLayout>

My main activity Xml code on which I have ListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:id="@+id/Team_Create_MainTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/btn_Create"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="Create_Team"
                android:text="@string/Team_Create_New" />

            <Button
                android:id="@+id/btn_ADD"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Team_Create_Add" />

            <Button
                android:id="@+id/btn_Edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Team_Create_Edit" />

            <Button
                android:id="@+id/btn_Back"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Team_Create_Back" />

        </TableRow>




        <com.example.fyp_api_8_team.SlideExpandableListView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="465dp" >

        </com.example.fyp_api_8_team.SlideExpandableListView>

    </TableLayout>

</LinearLayout>

My main Activity Code

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Create_Team_Form extends Activity {

    TextView txt;
    private String[] lv_arr = {};
    ArrayList<String> teamNames = new ArrayList<String>();
    ListView list;
    ListAdapter adapter;

    static String[] COUNTRIES;
    //ListView lv1;




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create__team__form);

        list = (ListView) this.findViewById(R.id.list);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_create__team__form, menu);
        return true;
    }

    public void Create_Team(View v) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("CreateTeam");
        alert.setMessage("Enter Team Name");

        // Set an EditText view to get user input
        final EditText input = new EditText(this);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                // OK
                String ans = input.getText().toString();
                if (ans == null || ans.length() == 0 || ans.equals("")) {

                } else {
                    String value = ans;
                    Add_TeamName_List(value);

                    Set_List();
                }

            }
        });

        alert.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        alert.show();

    }


    public void Add_TeamName_List(String Name) {
        teamNames.add(Name);

        Put_data_Array();

    }

    public void Set_List() {
         adapter = new ArrayAdapter<String>(this,
                R.layout.expandable_list_item, R.id.text, lv_arr);
        list.setAdapter(new SlideExpandableListAdapter(adapter,
                R.id.expandable_toggle_button, R.id.expandable));

        /*
        lv1.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_1, lv_arr));
                */
    }

    public void Put_data_Array() {
        lv_arr = new String[teamNames.size()];

        for (int i = 0; i < teamNames.size(); i++) {
            lv_arr[i] = teamNames.get(i);
        }
        Arrays.sort(lv_arr);

        put_Data_again_Arraylist();


    }

    public void put_Data_again_Arraylist()
    {

            teamNames.clear();  
        for (int i = 0; i < lv_arr.length; i++) {

            teamNames.add(lv_arr[i]);
        }

    }



    public void Team_Delete(View v)
    {

        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               teamNames.remove(position);
                ((BaseAdapter) adapter).notifyDataSetChanged();
            }
        });
    }

    public void Team_Details(View v)
    {

    }

Below I have attached the screenshot of my UI

Enter image description here

When I click the More button my Delete and Detail buttons are shown to the user If user Press the Delete button that row item should be deleted.

enter image description here

Waiting for the reply I am trying to solve this problem for quite a time now

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:19:22+00:00Added an answer on June 15, 2026 at 2:19 am

    – Always use ArrayList instead of String[] for holding the values which will be used by the ArrayAdapter as Collection are far more flexible than Arrays

    – You can simply remove the entry from ArrayList on clicking the delete button, and then do the notifyDataSetChanged() method.

    Eg:

    ArrayList<String> s = new ArrayList<String>();
    
    s.setList();   // A custom method to fill the list
    
    // assign your ArrayList to the ArrayAdpater here
    
    // set ArrayAdpater to ListView
    
    arrayadapter.notifyDataSetChanged();  // arrayadapter is of the ArrayAdapter which is 
                                          // set with your ArrayList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to delete a row from my JQGrid because I can't figure
I'm unable to delete my file, i have looked here but can't find the
I'm unable to delete record from sqlite db using Navicat. The error reads: `Error
I am using checkbox with ListView.Code is working fine. I strucked to get all
I am unable to get the selected radio button value in a form post.
Apparently, NSFileManager is unable to delete files created by mkstemp() . Here's some test
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject
I get the following error: Unable to create instance of class TestProject.TestClass. Error: System.Runtime.InteropServices.COMException:
Where you have a databound list of items and for each item you may
I am unable to delete a div with an id with a period or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.