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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:05:09+00:00 2026-06-06T12:05:09+00:00

I want to delete an array index from an array, then reload listView with

  • 0

I want to delete an array index from an array, then reload listView with my new array and then write a string to an existing file in android. I am using following code:

 OnItemLongClickListener longClickListener = new OnItemLongClickListener(){

            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {
                itemPosition = position;

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                alertDialogBuilder.setTitle("Warning");

                alertDialogBuilder
                .setMessage("Are you sure?")
                .setCancelable(false)
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        ArrayList<String> itemsList = new ArrayList<String>();
                        for(int i=0; i<items.length; i++){
                            itemsList.add(items[i]);
                        }

                        itemsList.remove(itemPosition);
                        items = new String[itemsList.size()];
                        for(int i=0; i<itemsList.size(); i++){
                            items[i] = itemsList.get(i);
                        }

                        adapter.notifyDataSetChanged();

                        String newData = "";

                        for(int i=0; i<items.length; i++){
                            newData = newData+items[i];
                            if(i < items.length-1){
                                newData = newData+"NEXTLINE";
                            }
                        }
                        // write string to existing file
                        try {
                            fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                            fos.write(newData.getBytes());
                            fos.close();
                        } catch (FileNotFoundException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                    }
                  })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

                return true;
            }

        };

when i click yes on alert then my app doesn’t respond and after some time my phone ask to kill the app? Can anybody please tell me that whats wrong with this code? 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-06-06T12:05:13+00:00Added an answer on June 6, 2026 at 12:05 pm

    the problem is in following snippt of code… MIght be your list have a too lagre of size and you are looping it thrice and in between you are also refreshing on list.

                 ArrayList<String> itemsList = new ArrayList<String>();
                        for(int i=0; i<items.length; i++){
                            itemsList.add(items[i]);
                        }
    
                        itemsList.remove(itemPosition);
                        items = new String[itemsList.size()];
                        for(int i=0; i<itemsList.size(); i++){
                            items[i] = itemsList.get(i);
                        }
    
                        adapter.notifyDataSetChanged();
    
                        String newData = "";
    
                        for(int i=0; i<items.length; i++){
                            newData = newData+items[i];
                            if(i < items.length-1){
                                newData = newData+"NEXTLINE";
                            }
    

    Try to debug and reduce code and loop on this click …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, let's say I want to delete from the array all continuous segments
I want to delete a file into recycle bin. I using this code. SHFILEOPSTRUCT
What is wrong here? I want delete an item from an array, but it
I want to filter and delete an item from an array. is it possible
I want to delete every second and third element from an array in Javascript.
All, I want to delete specific array elements of one array from the other.
If I want to dynamically create an int array in C++ and then delete
Delete an element from an array in php without array_search I want to delete
I want to delete DataRows from a DataTable. The rows to be deleted are
I want to delete an entry from my Database but it says it can't

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.