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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:17:56+00:00 2026-05-19T12:17:56+00:00

If I want to remove an item from my list view by tapping it,

  • 0

If I want to remove an item from my list view by tapping it, do I remove the object from the ArrayList I’m using with my ArrayAdapter, or do I remove the object directly from the adapter and call the notifyDatasetChange?

Also I want to store the data from the list on the disk, do I save the adapter or the arraylist I use?

Here is the code: The idea I’m going for is to save the data from the list and load it back when the activity launches again, however once this happens I cannot delete items from the list anymore.

public class EditKeywords extends ListActivity implements Serializable{

    private ArrayList<String> keyWordList;
    private EditText keywordEditText;
    private IconicAdapter adapter;
    private Button enterButton;
    private int position;
    private Button finishedButton;
    public static final String KEYWORDS = "keywords";
    public static final String ADAPTER = "adapter";


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.editkeyowords);
        getKeywordsAndAdapter();
        keywordEditText = (EditText) findViewById(R.id.keywordedittext);
        setListAdapter(adapter);

        enterButton = (Button) findViewById(R.id.enterkeywords);
        enterButton.setOnClickListener(enterButtonListener);

        finishedButton = (Button) findViewById(R.id.finishedbutton);
        finishedButton.setOnClickListener(finishedButtonListener);
    }

    public void onResume(){
    super.onResume();
    getKeywordsAndAdapter();
    }

    public void onPause(Bundle savedInstanceState){
    super.onPause();
    writeKeywordsAndAdapter();
    }


    public void getKeywordsAndAdapter(){
    try {
        InputStream fi = openFileInput(KEYWORDS);

        if (fi!=null) {
            ObjectInputStream in = new ObjectInputStream(fi);
                    keyWordList = (ArrayList<String>) in.readObject();
                    in.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }
    if(keyWordList == null){
        keyWordList = new ArrayList<String>();
    }

    try {
        InputStream fi = openFileInput(ADAPTER);

        if (fi!=null) {
            ObjectInputStream in = new ObjectInputStream(fi);
                adapter = (IconicAdapter) in.readObject();
                in.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }
    if(adapter == null){
        adapter = new IconicAdapter();
    }
    }

    public void writeKeywordsAndAdapter(){

    try {
        OutputStream fi = openFileOutput(KEYWORDS, 0);

        if (fi!=null) {
            ObjectOutputStream out = new ObjectOutputStream(fi);
                out.writeObject(keyWordList);
                out.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }

    try {
        OutputStream fi = openFileOutput(ADAPTER, 0);

        if (fi!=null) {
            ObjectOutputStream out = new ObjectOutputStream(fi);
            out.writeObject(adapter);
            out.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }


    }

    public void onListItemClick(ListView parent, View v,
        int aPosition, long id) {

        ImageView image = (ImageView) findViewById(R.id.icon1);
        image.setImageResource(R.drawable.delete);
        image.setOnClickListener(deleteImageListener);
        getListView().getChildAt(aPosition).invalidate();
        //adapter.notifyDataSetInvalidated();
        position = aPosition;
    }

    public void startHome() {
    Intent intent = new Intent(this, ECS.class);
    this.startActivity(intent);
    finish();
    }

    public class IconicAdapter extends ArrayAdapter<String> implements Serializable {
    private static final long serialVersionUID = 6175078429973952022L;


    IconicAdapter() {
        super(EditKeywords.this, R.layout.rowkeywords, keyWordList);
    }


    public View getView(int position, View convertView,ViewGroup parent) {
        LayoutInflater inflater=getLayoutInflater();

        View row=inflater.inflate(R.layout.rowkeywords, parent, false);
        TextView label=(TextView)row.findViewById(R.id.label1);

        label.setText(keyWordList.get(position));
        return(row);
    }
    }

    private OnClickListener enterButtonListener = new OnClickListener() {

    @Override
    public void onClick(View arg0){

        if(keywordEditText.getText().toString() != ""){
        boolean unique = true;
        for(String s : keyWordList){
            if(s.equals(keywordEditText.getText().toString())){
            unique = false; 
            }
        }
        if(unique == true){
            adapter.add(keywordEditText.getText().toString());
            keywordEditText.setText("");
            adapter.notifyDataSetChanged();
        }
        }
    }
    };

    private OnClickListener deleteImageListener = new OnClickListener() {

    @Override
    public void onClick(View arg0){
        //keyWordList.remove(position);
        adapter.remove(keyWordList.get(0));
        adapter.notifyDataSetChanged();
        writeKeywordsAndAdapter();


    }
    };

    private OnClickListener finishedButtonListener = new OnClickListener() {

    @Override
    public void onClick(View arg0){
       writeKeywordsAndAdapter();
       startHome();
    }
    };

}
  • 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-19T12:17:57+00:00Added an answer on May 19, 2026 at 12:17 pm

    What I did was edit the array list then set the setListAdapter(adapter) to a newly created adapter object.

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

Sidebar

Related Questions

I have a std::list of boost::shared_ptr<T> and I want to remove an item from
If i have IEnumberable<Car> list and i want to remove an item from this
Begginer android programer, I want add and remove item from String list when user
I want to remove objects from a list using linq, for example : public
I want to remove remove table row from table and subsequently remove the item
I want remove "Language" querystring from my url. How can I do this? (using
I have a drop down list in ASP.NET. I want to remove every item
In c#, when I want to remove some items from a list, i do
I'd like the user to be able to remove an item from a list
Possible Duplicate: Remove items from a list while iterating in Python I want to

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.