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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:20+00:00 2026-05-26T17:36:20+00:00

I have here a baseadapter based on what I saw in the API demos.

  • 0

I have here a baseadapter based on what I saw in the API demos. I want to dynamically add/remove items from the list, in this case adding from an intent called by a button, and removing from clicking on an imageview in the listview. And in this case, I would be adding/removing items from DATA[].
I have looked around for various AddItem() and or Remove() methods on SO and google, but have not really come up with much for this situation. Any help would be great. Here is the code:

public class myActivity extends Activity{
    private static final int CONTACT_PICKER_RESULT = 1001;  
    private static final String TAG = myActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ListView lv = (ListView)findViewById(R.id.listView1);
        lv.setAdapter(new myAdapter(this));     
        Button bAdd = (Button)findViewById(R.id.bAdd);
        bAdd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
        ........xxxx....xxxx....
        }
public class myAdapter extends BaseAdapter{
        private LayoutInflater mInflater;

        public myAdapter(Context context) {
            mInflater = LayoutInflater.from(context);

        }


        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return DATA.length;
        }


        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }


        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }


        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.row,null);
                holder = new ViewHolder();
                holder.text = (TextView) convertView.findViewById(R.id.txtTitle);
                holder.icon = (ImageView) convertView.findViewById(R.id.imgIcon);
                convertView.setTag(holder);


            } else {
                // Get the ViewHolder back to get fast access to the TextView
                // and the ImageView.
                holder = (ViewHolder) convertView.getTag();
            }
            holder.text.setText(DATA[position]);
            holder.icon.setImageResource(android.R.drawable.ic_delete);

            return convertView;
        }



        }


    static class ViewHolder {
        TextView text;
        ImageView icon;
    }
//this will not be hard-coded, jsut included for clarity
private static final String[] DATA ={
        "one","two","three" };
  • 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-26T17:36:20+00:00Added an answer on May 26, 2026 at 5:36 pm

    If all you need to to able to do is add/remove items from your DATA[] array, why not just replace the array with a simple List, implemented by an ArrayList for example.

    This would allow you to write click handlers for your adapter which add/remove items from the list as needed.

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

Sidebar

Related Questions

This is a related to a previous question I have asked here, see the
I have here a slight problem. We have written a big spring based application
I have a AutoCompleteTextView and a custom AutoCompleteTextView adapter. my list has 20 items
I have here a Windows Mobile-based PDA (Mobile Compia M3 Sky) equipped with a
I have an extended from BaseAdapter class which used as a custom Adapter for
I have Vector of elements that i set into BaseAdapter subclass and this adapter
I have list item with EditText in it, I don't know how many items
I have a list view with several ToggleButton items. When I click one, another
I have here an black/white png file of the dimensions 2156x1728 which I want
I have just been helped on a problem I have here . var win

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.