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 6654333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:22:41+00:00 2026-05-26T01:22:41+00:00

SORRY FOR THIS CONFUSION: UPDATED QUESTION: I’m trying to remove a list item from

  • 0

SORRY FOR THIS CONFUSION:
UPDATED QUESTION:
I’m trying to remove a list item from the listview. when the item is clicked, the alertdialog is shown. If i click OK, then the selected item must be removed from the listview.
My Code goes below:

case R.id.lvinc:
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Delete Event ");

        builder.setMessage("Delete this Event ?");
        builder.setPositiveButton("Ok, Delete",
                new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                  try
                  {
                     ???? //What code to delete the selected list item?




                  }catch(Exception e)
                  {
                      e.printStackTrace();
                  }
         }
                });

        AlertDialog alert = builder.create();
        alert.show();
        displaylist();
        break;

Any help is really appreciated and thanks in advance…

  • 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-05-26T01:22:42+00:00Added an answer on May 26, 2026 at 1:22 am

    I tried to solve it and got one solution pls go through the code below:

    listview.java

    public class listview extends Activity implements OnItemClickListener{
    
         ListView list;
         ListAdapter adapter;
         ArrayList<String> nameArray;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);//xml should have an ListView element
            nameArray   =   new  ArrayList<String>();
            nameArray.add("Item1");
            nameArray.add("Item2");
            nameArray.add("Item3");
            nameArray.add("Item4");
            nameArray.add("Item5");
            list = (ListView) findViewById(R.id.listView);
            list.setOnItemClickListener(listview.this);
            adapter=new ListAdapter(listview.this, nameArray);
            list.setAdapter(adapter);
        }
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            showDialog(arg2);
        }
        @Override
        protected Dialog onCreateDialog(final int id) {
            Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Delete Event")
                .setCancelable(true)
                .setPositiveButton("Ok, Delete",
                        new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            nameArray.remove(id);
                            adapter=new ListAdapter(listview.this, nameArray);
                            list.setAdapter(adapter);
                        }
                        })
                .setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
    
                        }
                        });
            AlertDialog dialog = builder.create();
            dialog.show();
            return super.onCreateDialog(id);
        }
    }
    

    //Adapter Class

    ListAdapter.java

    public class ListAdapter extends BaseAdapter {
    
        private Activity activity;
        private ArrayList<String> name;
        private static LayoutInflater inflater=null;
    
        public ListAdapter(Activity a, ArrayList<String> nameArray) {
            activity = a;
            name    =   nameArray;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        }
    
        public int getCount() {
            return name.size();
        }
    
        public Object getItem(int position) {
            return position;
        }
    
        public long getItemId(int position) {
            return position;
        }
    
        public static class ViewHolder{
            public TextView text;
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            View vi=convertView;
            ViewHolder holder;
            if(convertView==null){
                vi = inflater.inflate(R.layout.list_item, null);
                holder=new ViewHolder();
                holder.text=(TextView)vi.findViewById(R.id.title);
                vi.setTag(holder);
            }
            else
                holder=(ViewHolder)vi.getTag();
            holder.text.setText(name.get(position));
            return vi;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry bout the confusion this is what I am asking. I am trying to
me again. Sorry about this. Following on from my previous question (I think I
EDIT Sorry for the confusion, here is my updated question. I am using FindBin
Sorry this is not a very well defined question, I am thinking about an
Ok sorry this might seem like a dumb question but I cannot figure this
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry if this sounds like a really stupid question, but I need to make
Sorry if this is a comp-sci 101 question. I'm just unsure if I'm missing
Sorry if this question seems trivial to many here. In a C++ code there
Sorry if this is a stupid question... I've developed an application that creates absolute

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.