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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:12+00:00 2026-05-27T11:50:12+00:00

I am trying to insert list items dynamically into the list view. As list

  • 0

I am trying to insert list items dynamically into the list view. As list view is created and displayed on the screen now suppose i got one items from the server or some where, now i want to add this item in the same list view what i have displayed. How to do that ?? Is there any way to insert items dynamically in the displayed list view without creating the list agtain and again. And is there any way to change the status of list item, that means can we interact while it is displaying?? your’s reply will be appreciated. Thnx 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-27T11:50:13+00:00Added an answer on May 27, 2026 at 11:50 am

    Add whatever you want to the data structure (meaning the List) that is being used by your Adapter and then call notifiyDataSetChanged() on your Adapter

    With a regular ArrayAdapter it would be something like:

    MyAdapter adapter = new MyAdapter(this, R.layout.row, myList);
    listView.setAdapter(adapter);
    ...
    //make a bunch of changes to data
    list.add(foo);
    listView.getAdapter().notifyDataSetChanged();
    

    I can provide a more complicated example with a BaseAdapter as well.

    EDIT

    I created a little sample because this question seems to be pretty common.

    In my sample I did everything in one class, just to make it a bit easier to follow it all in one place.

    In the end, it’s very much a model-view-controller type situation. You can even run the actual project by cloning it from here: https://github.com/levinotik/Android-Frequently-Asked-Questions

    The essence of it is this:

    /**
     * This Activity answers the frequently asked question
     * of how to change items on the fly in a ListView.
     *
     * In my own project, some of the elements (inner classes, etc)
     * might be extracted into separate classes, but for clarity
     * purposes, I'm doing everything inline.
     *
     * The example here is very, very basic. But if you understand
     * the concept, it can scale to anything. You have complex
     * views bound to complex data wit complex conditions.
     * You could model a facebook user and update the ListView
     * based on changes to that user's data that's represented in
     * your model.
     */
    public class DynamicListViewActivity extends Activity {
    
        MyCustomAdapter mAdapter;
    
        @Override
        public void onCreate(Bundle state) {
            super.onCreate(state);
            ListView listView = new ListView(this);
            setContentView(listView);
    
            /**
             * Obviously, this will typically some from somewhere else,
             * as opposed to be creating manually, one by one.
             */
    
            ArrayList<MyObject> myListOfObjects = new ArrayList<MyObject>();
    
            MyObject object1 = new MyObject("I love Android", "ListViews are cool");
            myListOfObjects.add(object1);
            MyObject object2 = new MyObject("Broccoli is healthy", "Pizza tastes good");
            myListOfObjects.add(object2);
            MyObject object3 = new MyObject("bla bla bla", "random string");
            myListOfObjects.add(object3);
    
            //Instantiate your custom adapter and hand it your listOfObjects
            mAdapter = new MyCustomAdapter(this, myListOfObjects);
            listView.setAdapter(mAdapter);
    
            /**
             * Now you are free to do whatever the hell you want to your ListView.
             * You can add to the List, change an object in it, whatever.
             * Just let your Adapter know that that the data has changed so it
             * can refresh itself and the Views in the ListView.
             */
    
            /**Here's an example. Set object2's condition to true.
            If everyting worked right, then the background color
            of that row will change to blue
             Obviously you would do this based on some later event.
             */
            object2.setSomeCondition(true);
            mAdapter.notifyDataSetChanged();
    
    
    
        }
    
    
        /**
         *
         *  An Adapter is bridge between your data
         *  and the views that make up the ListView.
         *  You provide some data and the adapter
         *  helps to place them into the rows
         *  of the ListView.
         *
         *  Subclassing BaseAdapter gives you the most
         *  flexibility. You'll have to override some
         *  methods to get it working.
         */
        class MyCustomAdapter extends BaseAdapter {
    
            private List<MyObject> mObjects;
            private Context mContext;
    
            /**
             * Create a constructor that takes a List
             * of some Objects to use as the Adapter's
             * data
             */
            public MyCustomAdapter(Context context, List<MyObject> objects) {
                mObjects = objects;
                mContext = context;
            }
    
            /**
             * Tell the Adapter how many items are in your data.
             * Here, we can just return the size of mObjects!
             */
            @Override
            public int getCount() {
                return mObjects.size();
            }
    
            /**
             * Tell your the Adapter how to get an
             * item as the specified position in the list.
             */
            @Override
            public Object getItem(int position) {
                return mObjects.get(position);
            }
    
            /**
             * If you want the id of the item
             * to be something else, do something fancy here.
             * Rarely any need for that.
             */
            @Override
            public long getItemId(int position) {
                return position;
            }
    
            /**
             * Here's where the real work takes place.
             * Here you tell the Adapter what View to show
             * for the rows in the ListView.
             *
             * ListViews try to recycle views, so the "convertView"
             * is provided for you to reuse, but you need to check if
             * it's null before trying to reuse it.
             * @param position
             * @param convertView
             * @param parent
             * @return
             */
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                MyView view;
                if(convertView == null){
                    view = new MyView(mContext);
                } else {
                    view = (MyView) convertView;
                }
                /**Here's where we utilize the method we exposed
                 in order to change the view based on the data
                 So right before you return the View for the ListView
                 to use, you just call that method.
                 */
                view.configure(mObjects.get(position));
    
                return view;
            }
        }
    
    
        /**
         * Very simple layout to use in the ListView.
         * Just shows some text in the center of the View
         */
        public class MyView extends RelativeLayout {
    
            private TextView someText;
    
            public MyView(Context context) {
                super(context);
    
                LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                params.addRule(CENTER_IN_PARENT);
                someText = new TextView(context);
                someText.setTextSize(20);
                someText.setTextColor(Color.BLACK);
                someText.setLayoutParams(params);
                addView(someText);
            }
    
            /**
             * Remember, your View is an regular object like any other.
             * You can add whatever methods you want and expose it to the world!
             * We have the method take a "MyObject" and do things to the View
             * based on it.
             */
    
            public void configure(MyObject object) {
    
                someText.setText(object.bar);
                //Check if the condition is true, if it is, set background of view to Blue.
                if(object.isSomeCondition()) {
                    this.setBackgroundColor(Color.BLUE);
                } else {  //You probably need this else, because when views are recycled, it may just use Blue even when the condition isn't true.
                    this.setBackgroundColor(Color.WHITE);
                }
            }
        }
    
        /**
         * This can be anything you want. Usually,
         * it's some object that makes sense according 
         * to your business logic/domain.
         *
         * I'm purposely keeping this class as simple
         * as possible to demonstrate the point. 
         */
        class MyObject {
            private String foo;
            private String bar;
            private boolean someCondition;
    
    
            public boolean isSomeCondition() {
                return someCondition;
            }
    
    
            MyObject(String foo, String bar) {
                this.foo = foo;
                this.bar = bar;
            }
    
            public void setSomeCondition(boolean b) {
                someCondition = b;
            }
        }
    
    }
    

    If you grasp the concept here, you should be able to adapt (no pun intended) this to ArrayAdapters, etc.

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

Sidebar

Related Questions

I'm trying to insert items into a custom linked list, while keeping the list
I am trying to INSERT INTO a table using the input from another table.
I'm trying to insert a bunch of data into a SharePoint list. The List
I'm trying to insert a new item into a sorted list, entering the item
I am trying to insert new ListItems in a Sharepoint 2010 List already created.
I'm trying to break up an unordered list containing eight items into two lists,
So I am trying to Delete some items from the database before I Insert
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
Am trying to insert XML into XML Column.. getting following error: . Msg 6819,

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.