从数据库中获取数据并在Listview上显示

时间:2017-12-31 17:02:23

标签: java android sqlite

while (cursor.moveToNext())
                {
                    Message.massege(this,"Query "+cursor.getString(1)+"\n offer "+cursor.getString(0));
                    String[] fromFieldsname=new String[]{BankContract.Offers.Offers_COLUMN, BankContract.Offers.Query_COLUMN};
                    int[] toviewids=new int[]{R.id.offer_iid,R.id.Queriesofferlist_id};
                    SimpleCursorAdapter mycursoradapter;
                    mycursoradapter=new SimpleCursorAdapter(getBaseContext(), R.layout.offerlist, cursor, fromFieldsname, toviewids);
                    android.widget.ListView listview=(android.widget.ListView) findViewById(R.id.offerlist_id);
                    listview.setAdapter(mycursoradapter);
                    Message.massege(this, cursor.getString(0)+" Finally Done");
                    Log.d("all rows"," "+cursor.moveToNext());
                    if(cursor==null)
                    {
                        Message.massege(this,"offer column is null");
                        break;
                    }
                }

1 个答案:

答案 0 :(得分:0)

您应该创建一个单独的Model Class和recycleler视图适配器,然后创建该模型类的数组,并使用从游标获得的所有数据填充它并将其传递给适配器的构造函数。