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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:05:57+00:00 2026-06-09T20:05:57+00:00

Following is some test code , done to recreate a strange bug: After deleting

  • 0

Following is some test code , done to recreate a strange bug: After deleting some items from a ListView , it stops refreshing when data is invalidated. More items are deleted but list does not refresh. Even Log cat does not show debug messages for deletion. I will appreciate if any one could find out what’s wrong.

Item Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        android:orientation="horizontal">

    <TextView android:id="@+id/nameTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              />
    <Button android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete"
            />
</LinearLayout>

Item class:

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Item implements View.OnClickListener {
    private String name;
    private View itemView;
    private MyActivity owner;

    //--- getters--
    public String getName() {
        return name;
    }
    public View getView() {
        return itemView;
    }

    public Item(String n, Context c , MyActivity o)
    {
        //---store the name given--
        name = n;
        //---store reference to the owner activity--
        owner = o;

        //--- create a View for this item----
        LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.item,null);

        //---set up data to show--
        TextView nameTextView = (TextView) itemView.findViewById(R.id.nameTextView);
        Button deleteButton = (Button) itemView.findViewById(R.id.deleteButton);
        nameTextView.setText(name);

        //---set up events to be handled--
        deleteButton.setOnClickListener(this);

        Log.d("My_Test","Item: Hello world, my name is " + name);
    }

    //----request owner to delete this item---
    @Override
    public void onClick(View view) {
        Log.d("My_Test","Item:"+name+" requesting owner to delete me");
        owner.deleteItem(this);
    }

Activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
<ListView android:id="@+id/myListView"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          />
</LinearLayout>

Activity class:

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class MyActivity extends Activity {
    private ArrayList<Item> myItems;
    private ListView myListView;
    private ArrayAdapter<Item> myArrayAdapter;

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

        //-----adapter for item list----
        //----since each item has its own view , it just returns the same---
        myArrayAdapter = new ArrayAdapter<Item>(this,0){

            @Override
            public View getView(final int position, View convertView, ViewGroup parent)      {
              Item item = getItem(position);
              Log.d("My_Test","Adapter : View for Item: " + item.getName() +"is requested." );
              return item.getView();
            }

        };

        //-----set up my list view with the adapter------
        myListView = (ListView) findViewById(R.id.myListView);
        myListView.setAdapter(myArrayAdapter);

        //------add items-------
        //----each item has its own view and a reference to this activity as their owner----
        myArrayAdapter.add(new Item("Sunday", this, this));
        myArrayAdapter.add(new Item("Monday", this, this));
        myArrayAdapter.add(new Item("Tuesday", this, this));
        myArrayAdapter.add(new Item("Wednesday", this, this));
        myArrayAdapter.add(new Item("Thursday", this, this));
        myArrayAdapter.add(new Item("Friday", this, this));
        myArrayAdapter.add(new Item("Saturday", this, this));

        myArrayAdapter.notifyDataSetChanged();

    }

    //----- called by items requesting to be deleted from the item list----
    public void deleteItem(Item item) {
        myArrayAdapter.remove(item);
        Log.d("My_Test","Owner : Deleted item :" + item.getName());
        myArrayAdapter.notifyDataSetChanged();
    }
}

Looks like ListView stops re-drawing it self. Even when List Item is no more in the item array, and myAdapter.notifyDataSetInvalidated(); is called, The List Item stays visible , with further code execution some how blocked.

  • 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-09T20:05:59+00:00Added an answer on June 9, 2026 at 8:05 pm

    Use an ArrayAdapter to do this. Try something like this instead…

        import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.TextView;
    
    public class MyActivity extends Activity{
        private ListView myListView;
        private ArrayAdapter<Item> myArrayAdapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            myArrayAdapter = new ArrayAdapter<Item>(this,R.layout.item){    
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View returnedView = convertView;
    
                    //inflate your view here
                    if(returnedView == null){
                        LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        returnedView = inflater.inflate(R.layout.item,null);
                    }
    
                    final Item item = getItem(position);
    
                    //set the views
                    if(returnedView != null){
                        TextView nameTextView = (TextView) returnedView.findViewById(R.id.nameTextView);
                        nameTextView.setText(item.getName());
                        Button deleteButton = (Button) returnedView.findViewById(R.id.deleteButton);
                        deleteButton.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                remove(item);
                                notifyDataSetChanged();
                            }
                        });
    
                    }
    
                    return returnedView;
                }
            };
    
            myArrayAdapter.add(new Item("Sunday"));
            myArrayAdapter.add(new Item("Monday"));
            myArrayAdapter.add(new Item("Tuesday"));
            myArrayAdapter.add(new Item("Wednesday"));
            myArrayAdapter.add(new Item("Thursday"));
            myArrayAdapter.add(new Item("Friday"));
            myArrayAdapter.add(new Item("Saturday"));
    
            myListView = (ListView) findViewById(R.id.myListView);
            myListView.setAdapter(myArrayAdapter);
    
        }
    }
    
    public class Item{
    
        private String name;
    
        public Item(String n){
            this.name = n;
        }
    
        public String getName() {
            return name;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I tried following some of the code from here and here , but I
I have a JMeter test plan with following http request samplers. Login Call some
following some example from Microsoft I created my custom MembershipProvider in my MVC application
I was following some Java code to do image processing on bitmaps and found
Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here
I am mainly from a Sql Server background, and following some issues with getting
all. I wrote the following simple code to test scala.actors._: // java version 1.7.0_02
Consider the following code: LargeObject getLargeObject() { LargeObject glo; // do some initialization stuff
I have done some code in C that happily send the full backtrace with

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.