[JAVA] I updated the Kiratto Pri Chan coordination management app!

I updated it from this article I wrote before (Kiratto Pri Chan's coordination management app).

Updated part

Put the read part of the list into a ** SQLite database! ** **

Previously, I wrote it in the source one by one, so get the database created with SQLite and see it in the list view of the application.


     private class ListShowClickListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            //Create database helper object
            DatabaseHelper helper = new DatabaseHelper(PrichanJewel1.this);
            //Create database connection object
            try (SQLiteDatabase db = helper.getWritableDatabase()) {
                String sql = "select * from prij1corde order by _id";
                Cursor cursor = db.rawQuery(sql, null);
                String[] column = {"card_name", "card_own"};
                int[] cardList = {android.R.id.text1, android.R.id.text2};
                SimpleCursorAdapter adapter = new SimpleCursorAdapter
                        (PrichanJewel1.this, android.R.layout.simple_expandable_list_item_2,
                                cursor, column, cardList, 0);
                lvJprichan.setAdapter(adapter);
            }
        }
    }

Now you can access the database already created in SQLite, get the list and display it in the list view. In the case of updating, it was done in the same way.


        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
            //Get the long pressed position
            Cursor item = (Cursor)lvJprichan.getItemAtPosition(position);
            //Get the list name at the obtained position (here, get the card name)
            String card_name = item.getString(item.getColumnIndex("card_name"));
            //Create database helper object
            DatabaseHelper helper = new DatabaseHelper(PrichanJewel1.this);
            //Create database connection object
            try (SQLiteDatabase db = helper.getWritableDatabase()) {
                String upSql = "update prij1corde set card_own = 'Possessed' where card_name = '" + card_name + "'";
                SQLiteStatement stmt = db.compileStatement(upSql);
                stmt.executeUpdateDelete();
            }
            Toast.makeText(PrichanJewel1.this,
                    "Completion of registration!",Toast.LENGTH_SHORT).show();
            return true;
        }

The database helper is Thinking of male college students: Make your own SQLite Database file available on android from assets So, I use the source code introduced almost as it is. This article was helpful for getting the list.

Simple example of displaying the value obtained by sqlite in ListView

How did you do that?

I couldn't come up with a good idea, and I was inspired by the fact that I made a similar mechanism with Java and PostgreSQL in the middle of it. ** "Isn't it possible to incorporate it into the database?" ** When. I hadn't done it at all, so I did a lot of research and tried it with half confidence, but it went well, so that's what happened.

that's all.

Recommended Posts

I updated the Kiratto Pri Chan coordination management app!
I made an app for myself! (Reading management app)