如何使用for循环来匹配sqlite数据库数据 [英] How can use for loop to match with sqlite database data

查看:804
本文介绍了如何使用for循环来匹配sqlite数据库数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望显示结果,如果我的sqlite数据库获得两行数据,它将数字计为2,那么for循环将循环数字超过两个



< pre lang =java> viewPager.setAdapter(adapter);
字符串 CountQuery = SELECT * FROM Category ;
db = new DBController(MainActivity。 this );
SQLiteDatabase db2 = db.getReadableDatabase();
final 光标cursor1 = db2.rawQuery(CountQuery,null);
{
int num = cursor1.getCount();
int ans = num;
for int i = 8; ans< i; num ++){

textview.settext(ans);
}





我的尝试:



当我尝试循环变量时我会卡在6应循环直到7

解决方案

是的因为你正在测试<$的值c $ c> ans 反对 i 的值,但这些变化都不在您的循环中。


i want show result like if my sqlite database get two row of data it counting number as 2 then the for loop will looping the number more than two

viewPager.setAdapter(adapter);
    String CountQuery = "SELECT * FROM Category";
    db = new DBController(MainActivity.this);
    SQLiteDatabase db2 = db.getReadableDatabase();
    final Cursor cursor1 = db2.rawQuery(CountQuery, null);
    {
        int num = cursor1.getCount();
        int ans = num;
        for(int i =8 ; ans<i ; num++) {

            textview.settext(ans);
        }



What I have tried:

when i try to loop the variable i will stuck at 6 should be loop until 7

解决方案

Yes because you are testing the value of ans against the value of i, but neither of these changes within your loop.


这篇关于如何使用for循环来匹配sqlite数据库数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆