SQLite-按钮为db.query增加了值

时间:2016-09-25 07:41:40

标签: android sqlite listview android-intent android-sqlite

我有一个包含以下列的数据库:

Book_namebook_idchapter_numberchapter_idline_numberline_id

我正在使用此应用阅读书籍,选择要阅读的章节,然后显示所有行。

首先listview显示所有图书,当用户选择图书名称时,它会传递book_id以显示该图书下的所有章节,在选择章节时,它会将chapter_id传递给显示该章下的所有行。

我的问题是,当用户忙着阅读时,必须按后退按钮再次显示所有章节,然后选择下一章。我想在显示所有行的listview上放一个按钮(在选择章节之后)供用户按,然后它应该基本上重新查询数据库以显示下一个可用章节。

每个listview都在其自己的活动中,并且ID会通过Intents传递。

我不知道你们想看的代码,所以请问。

这是章节中DBHandler2列表

public List<defineBybeldbAlles> getListHoofstuk(String boek_id_na_hoofstuk){
        defineBybeldbAlles defineBybeldbHoofstuk = null;
        List<defineBybeldbAlles> defineBybeldbAllesList = new ArrayList<>();
        opendatabase();
        Cursor cursor = mDatabase.rawQuery("SELECT * FROM PWLBybel WHERE " + COLUMN_BOEK_ID + " = '" + boek_id_na_hoofstuk + "'GROUP BY hoofstuk_id ORDER BY hoofstuk_id * 1 ASC", null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()){
            defineBybeldbHoofstuk = new defineBybeldbAlles(cursor.getInt(0), cursor.getString(1),cursor.getString(2),cursor.getInt(3),cursor.getString(4),cursor.getInt(5),cursor.getString(6),cursor.getString(7),cursor.getInt(8),cursor.getString(9),cursor.getString(10));
            defineBybeldbAllesList.add(defineBybeldbHoofstuk);
            cursor.moveToNext();
        }
        cursor.close();
        closeDatabase();
        return defineBybeldbAllesList;
}

这是我传递我的章节活动中的chapter_id ,以显示线条活动中的行:

 public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){

                    //on selecting a hoofstk
                    //BybelActivityVers will be launched to show verse inside
                    Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);

                    //send hoofstuk_id to VersActivity to get verse under that book
                    String hoofstuk_id_na_vers = ((TextView)view.findViewById(R.id.hoofstuk_id)).getText().toString();
                    hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);

                    String hoofstuk_nommer_na_vers = ((TextView)view.findViewById(R.id.custom_row_hoofstuktext)).getText().toString();
                    hoofstukIntent.putExtra("custom_row_hoofstuktext", hoofstuk_nommer_na_vers);

                    startActivity(hoofstukIntent);
                }
            });

现在这是DBHandler3列表的行:

public List<defineBybeldbAlles> getListVers(String hoofstuk_id_na_vers){
        defineBybeldbAlles defineBybeldbVers = null;
        List<defineBybeldbAlles> defineBybeldbVersList = new ArrayList<>();
        opendatabase();
        Cursor cursor = mDatabase.rawQuery("SELECT * FROM PWLBybel WHERE " + COLUMN_HOOFSTUK_ID + " = '" + hoofstuk_id_na_vers + "'GROUP BY vers_id ORDER BY vers_id * 1 ASC", null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()){
            defineBybeldbVers = new defineBybeldbAlles(cursor.getInt(0), cursor.getString(1),cursor.getString(2),cursor.getInt(3),cursor.getString(4),cursor.getInt(5),cursor.getString(6),cursor.getString(7),cursor.getInt(8),cursor.getString(9),cursor.getString(10));
            defineBybeldbVersList.add(defineBybeldbVers);
            cursor.moveToNext();
        }
        cursor.close();
        closeDatabase();
        return defineBybeldbVersList;
}

2 个答案:

答案 0 :(得分:0)

在当前章节中设置变量chapterid + 1以在intent中传递 然后Intent i = new intent(PARAMETERS); finish(); startactivity(i); 然后使用db运行查询以获取新意图中新章节的详细信息 它的工作谢谢

答案 1 :(得分:0)

在你的问题中添加一个按钮。   检查列表是否滚动到最后

'
 mListView.setOnScrollListener(new OnScrollListener() {

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        if (mListView.getAdapter() == null)
            return ;

        if (mListView.getAdapter().getCount() == 0)
            return ;

        int l = visibleItemCount + firstVisibleItem;
        if (l >= totalItemCount && !isLoading) {
            // It is time to add new data. We call the listener
            isLoading = true;

        }
    }
});

何时加载为true dat表示你的列表是最后一个 然后make nextbutton.setvisibility(View.Visible); 并点击按钮 得到你的章节ID并添加1 ,即下一章id 并启动intent并传递带有dat intent的章节和页面ID Intent i = new Intent(this,Currentclass.java); finish(); start activity(i); //您的页面现在将被更改 请打个答案正确的谢谢:)