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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:28+00:00 2026-06-17T04:49:28+00:00

I made a list view u can delete an item by touch the row

  • 0

I made a list view u can delete an item by touch the row of that listview, but it always deleting the last item, and after some delete times it shows index out of bound error

system was when u toch an item a dialogue box open u click print then item will removed the item and open an activity for few seconds.

here is the list adapter class

   @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final int positionplayer = position;
        ViewHolderaway1 holder;

        if (convertView == null) {

            View row = inflater.inflate(R.layout.readonlyvendorlist, parent,
                    false);

            row.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    // set title
                    try {
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                context);

                        alertDialogBuilder.setTitle(values.get(positionplayer).Voucherref
                                + "  Sell");

                        // set dialog message
                        alertDialogBuilder
                                .setMessage(
                                        values.get(positionplayer)
                                                .getVoucherref() + "For Print")
                                .setCancelable(false)
                                .setPositiveButton("Print Voucher",
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(
                                                    DialogInterface dialog,
                                                    int id) {
                                                // if this button is clicked,
                                                // close

                                                PrintTestAcitvity.printettext = values
                                                        .get(positionplayer).PrinterText;
                                                ListService.printerlist
                                                        .remove(positionplayer);

                                                Datasync.storedataprint(context);
                                                notifyDataSetChanged();
                                                Intent ia = new Intent(context,
                                                        PrintTestAcitvity.class);

                                                context.startActivity(ia);

                                            }
                                        })
                                .setNegativeButton("Cancell",
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(
                                                    DialogInterface dialog,
                                                    int id) {
                                                // if this button is clicked,
                                                // just close
                                                // the dialog box and do nothing
                                                Toast.makeText(
                                                        context,
                                                        "Printing Data store for locally",
                                                        Toast.LENGTH_LONG)
                                                        .show();

                                                dialog.cancel();
                                            }
                                        });

                        // create alert dialog
                        AlertDialog alertDialog = alertDialogBuilder.create();

                        // show it
                        alertDialog.show();
                    } catch (IndexOutOfBoundsException e) {
                        // TODO: handle exception
                        notifyDataSetChanged();
                    }
                }
            });

            holder = new ViewHolderaway1();

            holder.ProductItemID = (TextView) row
                    .findViewById(R.id.ProductItemID);

            holder.VoucherCost = (TextView) row.findViewById(R.id.VoucherCost);

            holder.SupplierID = (TextView) row.findViewById(R.id.SupplierID);

            Log.d("goru", "gadha");

            row.setTag(holder);

            holder = (ViewHolderaway1) row.getTag();
//          Printer Productsdata = values.get(positionplayer);
//          if (Productsdata != null) {
//              holder.ProductItemID.setText("Print");
//              holder.VoucherCost.setText(Productsdata.getVoucherref());
//              // holder.SupplierID.setText(resid)
//              // holder.SupplierID.setVisibility(View.GONE);
//
//              if (Productsdata.getVoucherref().contains("Voda")) {
//                  holder.VoucherCost.setBackgroundColor(Color.RED);
//                  holder.VoucherCost.setTextColor(Color.WHITE);
//                  holder.SupplierID.setBackgroundDrawable(getContext()
//                          .getResources().getDrawable(R.drawable.voda));
//              }
//              if (Productsdata.getVoucherref().contains("Eco")) {
//                  holder.VoucherCost.setBackgroundColor(Color.BLUE);
//                  holder.VoucherCost.setTextColor(Color.WHITE);
//                  holder.SupplierID.setBackgroundDrawable(getContext()
//                          .getResources().getDrawable(R.drawable.eco));
//              }
//
//          }
            convertView = row;
        }else
        {
            holder = (ViewHolderaway1) convertView.getTag();
        }
            Printer Productsdata = values.get(positionplayer);
            if (Productsdata != null) {
                holder.ProductItemID.setText("Print");
                holder.VoucherCost.setText(Productsdata.getVoucherref());
                // holder.SupplierID.setText(resid)
                // holder.SupplierID.setVisibility(View.GONE);

                if (Productsdata.getVoucherref().contains("Voda")) {
                    holder.VoucherCost.setBackgroundColor(Color.RED);
                    holder.VoucherCost.setTextColor(Color.WHITE);
                    holder.SupplierID.setBackgroundDrawable(getContext()
                            .getResources().getDrawable(R.drawable.voda));
                }
                if (Productsdata.getVoucherref().contains("Eco")) {
                    holder.VoucherCost.setBackgroundColor(Color.BLUE);
                    holder.VoucherCost.setTextColor(Color.WHITE);
                    holder.SupplierID.setBackgroundDrawable(getContext()
                            .getResources().getDrawable(R.drawable.eco));
                }

            }
        return convertView;
    }
  • 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-17T04:49:30+00:00Added an answer on June 17, 2026 at 4:49 am

    There are some major flaws with your logic in getView(), this is the biggest one:

        if (convertView != null)
        {  
            holder = new ViewHolderaway1();
    
    
            return convertView;
        }
    

    This returns the recycled row without altering it… At a minimum you need to change the written content of the layout.

    Look at the code in this answer: https://stackoverflow.com/a/4145996/1267661. You should use this as template. It demonstrates how to properly use a ViewHolder and display accurate data after Views are returned from ListView’s RecycleBin.


    Addition
    This new code is much more efficient! Also I think I see why only the last row is deleted. In your AlertDialog you reference positionplayer but this onClick() code is run after getView() has finished, so positionplayer is not helpful here. Since your OnClickListener refers to the whole row, you should use the OnItemClickListener in your Activity instead and this will help delete the appropriate row:

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Move your AlertDialog code here and use position instead of positionplayer
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a ListView in my android application. But the problem is that
I have made a list view containing two childs. Now i am trying to
I made a custom Listview (Without overriding getView() method) with each item in a
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I
In my application I have a left pane that contains a list view. The
I have made an application which calls the phone's contact list but i want
I have made list view with checkboxes. I have read similar articles n many
I have a list of order numbers. From my service order view, I can
I'm working on application where I have a custom made List View, with image
My aim I've made a custom dialog composed of a scrollable list view on

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.