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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:32:45+00:00 2026-05-30T21:32:45+00:00

My Listview gets information saved on a local database and displays the information. I

  • 0

My Listview gets information saved on a local database and displays the information. I am having altering what happens when my listview items are clicked. I want to delete them, can anybody assist me with this matter, while using my code? Thank you in Advance!

public class Notepad extends ListActivity {
    public static final int INSERT_ID = Menu.FIRST;
    EditText notes;
    Button add;
    ListView lv;
    String currentDateTimeString = DateFormat.getDateInstance().format(
            new Date());

    private NotesDbAdapter mDbHelper;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notepad_list);
        mDbHelper = new NotesDbAdapter(this);
        mDbHelper.open();
        fillData();
        Button add = (Button) findViewById(R.id.addNote);
        // ListView lv = (ListView) findViewById(R.id.list);

        add.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                createNote();

            }
        });
        // lv.setOnItemClickListener(new OnItemClickListener() {
        //
        // public void onItemClick(AdapterView<?> parent, View view,
        // int position, long id) {
        // // When clicked, show a toast with the TextView text
        //
        // try {
        // Toast.makeText(getApplicationContext(),
        // ((TextView) view).getText(), Toast.LENGTH_SHORT)
        // .show();
        //
        // } catch (ClassCastException e) {
        // Toast.makeText(getApplicationContext(), "Error",
        // Toast.LENGTH_SHORT).show();
        // }
        //
        // };
        //
        // });
    }

    private void createNote() {
        EditText notes = (EditText) findViewById(R.id.note);
        String noteName = notes.getText().toString();
        Calendar c = Calendar.getInstance();
        int seconds = c.get(Calendar.SECOND);
        int minutes = c.get(Calendar.MINUTE);
        int hour = c.get(Calendar.HOUR);
        mDbHelper.createNote(noteName + " Entered at " + hour + ":" + minutes
                + ":" + seconds, "");

        fillData();
    }

    private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = mDbHelper.fetchAllNotes();
        startManagingCursor(c);

        String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
        int[] to = new int[] { R.id.text1 };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
                R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }
}

My ListView:

   <ListView
        android:id="@id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="402dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/note" >
    </ListView>
  • 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-30T21:32:46+00:00Added an answer on May 30, 2026 at 9:32 pm

    What I do in my Apps, is override the SimpleCursorAdapter.setViewBinder() to set the Tag of Views inside the ListView with the ID (_ID) from the DB and delete this ID from the DB in the setOnItemClickListener() and refresh the Adapter. Something like this:

            SimpleCursorAdapter notes = new SimpleCursorAdapter(this, 
                    R.layout.notes_row, c, from, to); 
    
        notes.setViewBinder(new SimpleCursorAdapter.ViewBinder() { 
    
    public boolean setViewValue(View view, Cursor cursor, int column) 
    { 
    TextView tv = (TextView) view; 
    view.setTag=cursor.getInt(cursor.getColumnIndex ("_id")); // You need to include the _id in the query
    tv.setText(String.Valueof(cursor.getInt(cursor.getColumnIndex (NotesDbAdapter.KEY_TITLE ))));
    return true; 
    } 
    });
    
             lv.setOnItemClickListener(new OnItemClickListener() { 
    
             public void onItemClick(AdapterView<?> parent, View view, 
             int position, long id) { 
    
             TextView tv=(TextView) view;
         String ID=view.getTag();
        // Delete ID from the DB
        notes.notifyDataSetChanged(); 
    
             }; 
    
             });    
        setListAdapter(notes); 
    
    
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a ListView with a custom adapter that gets information describing the
I have a ListView that gets updated frequently, at irregular intervals. I want it
I have a ListView which sometimes I need to put around 10000 items in.
So I have a ListView with an upper limit of about 1000 items. I
I have a ListView on a page that displays a list of widgets. When
while scroll the listview, the Layouts background gets flickering. that is the layout is
Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
Overview: I have an Expandable List View which displays items of the type ToDoElement
I have the variable string (user gets to set it via a ListView with
I want the ability to auto stretch the listview control column when the form

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.