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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:49:22+00:00 2026-05-18T20:49:22+00:00

My app contains a listview. Each item in listview has a delete button. But

  • 0

My app contains a listview. Each item in listview has a delete button. But delete button could not delete an item in listview. Please tell me how can i delete an item in a listview and also in database.my.

My source:

public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
       setContentView(R.layout.sharefolioedit);
       Log.e("string",s.toString());
       add = (ImageButton) findViewById(R.id.add);
       add.setOnClickListener(this);
       done = (Button) findViewById(R.id.done);
       done.setOnClickListener(this);

       getList();

       }


     public void onCreate1(Bundle savedInstanceState){
           super.onCreate(savedInstanceState);
           delete= (ImageButton) findViewById(R.id.delete);
           delete.setOnClickListener(this);
     }
     protected void onListItemClick(ListView l, ImageButton delete, int position,long id) {
            super.onListItemClick( l, delete, position, id);
             ID=id;
                 final Integer index =l.getSelectedItemPosition();
             Log.e("delete method","delete");

                Log.e("ID value",index.toString());
                new AlertDialog.Builder(ShareFolioEditActivity.this) 
                 .setTitle("Delete")
             .setMessage("Are you sure ??? ")
                     .setNeutralButton("no",null)
                     .setPositiveButton("yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int whichButton) {
             confirmdelete(index);                
            }
        })      .show();
             }

            public void myClickHandler(View v) {
             {
//               int position = 0;
//              onListItemClick(lv, delete, position, ID);
//               ID=id;
                Log.e("delete method","delete");

                final Integer a = new Integer(v.getId());
                Log.e("ID value",a.toString());
                new AlertDialog.Builder(ShareFolioEditActivity.this) 
                 .setTitle("Delete")
             .setMessage("Are you sure ??? ")
                     .setNeutralButton("no",null)
                     .setPositiveButton("yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int whichButton) {
             confirmdelete(a);                
            }
        })      .show();
             }
        }

    public void onClick(View v) {
        if(v.equals(add))
        {
            Intent in=new Intent(ShareFolioEditActivity.this,AddCategory.class);
            startActivity(in);
        }
        if(v.equals(done))
        {  
            Intent i=new Intent(ShareFolioEditActivity.this,ShareFolioActivity.class);
            startActivity(i);
        }
    }

    public void confirmdelete(int index)
    {  
       db.delete("sharelist", "_id="+index, null);
       Toast.makeText(this, "row deleted"+index, Toast.LENGTH_SHORT).show();
       Bundle b=null;
       onCreate(b);
    }

     public void getList()
     {  int x = 0;
        String where=null;
         csh=new createSqliteHelper(this);
        try{

            //db.open();
       db=csh.getReadableDatabase();  
        }catch(Exception e){
            System.out.println(e);
        }  
        if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
            where=getIntent().getStringExtra(SearchManager.QUERY);
            x=1;
        }
      if(x==1)
      {
         cur=db.rawQuery("SELECT * FROM sharelist where category LIKE '%"+where+"%'",null); 
      }else{
      cur=db.rawQuery("SELECT * FROM sharelist ORDER BY category",null);}
      Log.e("cursor",cur.toString()); 
    SimpleCursorAdapter list=new SimpleCursorAdapter(this,R.layout.edititems,cur,s,i ); 
    getListView();
    setListAdapter(list);

     }
}

The sharefolioedit xml layout is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    <TextView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text"
    android:text="CATEGORIES"
    android:layout_centerHorizontal="true"
    />

    <Button 
        android:id="@+id/done"
        android:text="Done" 
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true" 
        android:layout_width="90px"
        android:layout_height="20px"
        android:layout_above="@id/android:list" />
        <ImageButton 
        android:id="@+id/add"
        android:text="Add" 
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" 
        android:layout_width="80px"
        android:layout_height="20px"
        android:layout_above="@id/android:list" 
        android:src="@drawable/addicon"/>

    <ListView android:layout_width="500px"
        android:layout_height="700px" 
        android:id="@id/android:list"
        android:layout_alignParentBottom="true" 
        />
 </RelativeLayout>

The edititems.xml is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <ImageButton
    android:id="@+id/delete"
    android:layout_width="70px"
    android:paddingLeft="2px"
    android:paddingRight="2px"
    android:paddingTop="2px"
    android:text="Delete"
    android:layout_height="wrap_content"
    android:onClick="myClickHandler"
    android:src="@drawable/removeicon"
    />

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">

    <TextView
    android:id="@+id/category"
    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    android:text=""
    android:layout_toRightOf="@+id/catagory"
     />
     </RelativeLayout>
</LinearLayout>

In edititems.xml i defined a delete button also so please check and tell me solution.

  • 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-18T20:49:22+00:00Added an answer on May 18, 2026 at 8:49 pm

    In your confirmdelete method, after the db.delete use an AsyncTask to query the database and obtain a new Cursor in the doInBackground method. Then in the onPostExecute method call changeCursor on your SimpleCursorAdapter which you have called list which should be a class level field instead of a local field so all your methods can access it. This will tell the ListView that the data in the adapter has changed and it needs to refresh itself. There is no need to call onCreate in your confirmdelete method at the bottom.

    Here is some code:

    private class UpdateCursor extends AsyncTask<Void, Void, Cursor> {
        protected Cursor doInBackground(URL... urls) {
            Cursor result = db.query(...);
            return result;
        }
    
        protected void onPostExecute(Cursor result) {
            list.changeCursor(result);
        }
    }
    

    Good Luck.

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

Sidebar

Related Questions

Hallo all, I have a ListView which contains a Button in each line. The
My Django app has a Person table, which contains the following text in a
I'm writing an app that contains the following tables: (1) employee_type, (2) employee and
I'm writing a small GUI app that contains some editor functionality, and something that
The setup of my Windows Mobile app is created using VS2008. It contains a
My app has many controls on its surface, and more are added dynamically at
An app I'm writing always crashes on a clients computer, but I don't get
Here's the problem. In my app, I have 5 tabs which contains activities. In
I have an MFC sdi app that uses a splitter window to contain a
My app is installed via NSIS. I want the installer to install the program

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.