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

  • Home
  • SEARCH
  • 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 8373305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:38:44+00:00 2026-06-09T14:38:44+00:00

I have used a List and an Arrayadapter to put strings in a Listview.

  • 0

I have used a List and an Arrayadapter to put strings in a Listview. Now I want to remove the selected Item. I have tried the following code, but it’s not working well. How can I fix this?

Here’s my code:

TextView t1;
String[] temp;
mylist = (ListView) findViewById(R.id.list);
final List<String> wordList = Arrays.asList(temp);
adapter = new ArrayAdapter<String>(this,
                                   android.R.layout.simple_list_item_multiple_choice, 
                                   wordList);
delete.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
       int index = mylist.getSelectedItemPosition();
       int count=mylist.getCount();
       for(int i=0;i<=count;i++) {
           if (index >= 0) {
               t1.setText(wordList.remove(index));
           }
           adapter.notifyDataSetChanged();
       } 
   }
});

Here’s more source code:

    public class Edit extends Activity {
        SharedPreferences sharedpref;
        ListView mylist;
        String[] temp;
        String name, 
        ArrayAdapter<String> adapter;
        Button save, delete, cancel;
        TextView t1;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.edit);
            mylist = (ListView) findViewById(R.id.list);
            cancel = (Button) findViewById(R.id.cancel1);
            save = (Button) findViewById(R.id.save1);
            delete = (Button) findViewById(R.id.delete1);
            t1=(TextView)findViewById(R.id.textView1);
            sharedpref = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext());
            name = sharedpref.getString("Visible_selected", "");

            String delimiter = "\n";
            temp = name.split(delimiter);

            mylist.setItemsCanFocus(true);
            mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
             final List<String> wordList = Arrays.asList(temp);  

            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_multiple_choice, wordList);
            mylist.setAdapter(adapter);
            save.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub

                }
            });

            delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    mylist.setOnItemClickListener(new OnItemClickListener() {
                        private String getSelectedItemOfList;
                        @Override
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                int arg2, long arg3) {
                            // TODO Auto-generated method stub
                             getSelectedItemOfList = sortedList.get(arg2).getStr_movieParam();


                }
            });

            cancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                }
            });

        }

    }

Here’s my updates code:

enter code here

delete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
         adapter.remove(getSelectedItemOfList);
         adapter.notifyDataSetChanged();
            }
        });
        mylist.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                SparseBooleanArray checkedPositions =mylist.getCheckedItemPositions();
                if(checkedPositions.get(arg2)==true){
                getSelectedItemOfList = (String) mylist.getItemAtPosition(arg2);
                t1.append(getSelectedItemOfList.toString()+"\n");}
            }
        });
  • 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-09T14:38:45+00:00Added an answer on June 9, 2026 at 2:38 pm

    Try to implement the onitemclickListener and get the item id and delete the item clicked in the arrayadapter and next call adapter.notifyDataSetChanged();

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

Sidebar

Related Questions

I have AutoCompleteTextView attached to my view, and used ArrayAdapter to populate for list
I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have created a list. Now when I click on the list item I
i have used setColumns function to show/hide columns dynamically on client-side. now i want
I have used a code given in tutorial http://mylifewithandroid.blogspot.com/2010/12/expandable-list-and-checkboxes.html I have attached an image
I have an application that uses hibernate. I did the following: Used List to
I have used a list view that uses a grid view in WPF. I
Friends i'm using string builder for generating Passenger List in which i have used
I have a chess game that originally used an stl list to store the

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.