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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:07:14+00:00 2026-05-30T08:07:14+00:00

I created a SQLiteDatabase where I can see the items with the ‘View’ Button

  • 0

I created a SQLiteDatabase where I can see the items with the ‘View’ Button and clicking on it, I get the whole database into a ListView. In this ListView I would like the items to be clickable and if I click on them, I want to add a new entry to it with the same name, but another id. My code so far:

ListView lv;
ArrayList<String> todoItems = new ArrayList<String>();


    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);


        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, todoItems));
          ListView lv = getListView();
          lv.setTextFilterEnabled(true);

        hornot info = new hornot(this);
        info.open();

        Cursor c = info.getAllTitles();
        if (c.moveToFirst())
        {
        do{


            todoItems.add(c.getString(0) + " " + c.getString(1) + " " + c.getString(2));
            }while (c.moveToNext());
        }
            if (todoItems.size() > 0)
            {
        lv.setAdapter(new ArrayAdapter<String>(sqview.this,android.R.layout.simple_list_item_1, todoItems));
            }


            lv.setOnItemClickListener(new OnItemClickListener(){
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                      //-/////////////////////////
                    }
                  });

            info.close(); 

        }

As you see, I put the database items into an array, then I put them into a ListView. With an upgrade button I can add items, so I think I need to do something same here.
In the dbhelper the createEntry function:

public long createEntry(String name, String hotness) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_NAME, name);
        cv.put(KEY_HOTNESS, hotness);
        return ourDatabase.insert(DATABASE_TABLE, null, cv);        
    }

In the main.java I convert the EditTexts to Strings then put the values into the database:

    String name = sqlName.getText().toString();
    String hotness = sqlHotness.getText().toString();

    hornot entry = new hornot(dbhelp.this);
    entry.open();
    entry.createEntry(name, hotness);
    entry.close();

So what should I write for the onItemClick function?

  • 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-30T08:07:16+00:00Added an answer on May 30, 2026 at 8:07 am

    In the onItemClick() method you have the position parameter that indicates the position(in the adapter) of the list row that was clicked. You could then use getItemAtPosition on the ListView to get the data from the row:

    lv.setOnItemClickListener(new OnItemClickListener(){
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
         String rowData = (String) lv.getItemAtPosition(position); //you'll need to make the lv as final
         String[] data = rowData.split(" "); //split the result using the spaces (so you could obtain the name, hotness and the other string you use)
         entry.createEntry(data[0], data[1]);
    }
    

    I don’t know your database structure so I can’t recomend you something about unique id.

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

Sidebar

Related Questions

I created a SQLite database on Android device. The program can read/write to database
I've created a custom view in an SQLite database for an Android application. I'm
I created a sample application using android sqlite database, my requirements are How can
I have an SQLite database. I created the tables and filled them with a
I am new to using the SQLite database in iphone apps. I have created
I've created an SQLiteDatabase in my app and populated it with some data. I
When my app is created, my database is copied from the assets folder to
I've followed a standard tutorial for building a database with Android. I've created a
I have creating a login form where I have created sqlite database,in this I
I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE

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.