从android SQL lite数据库中选择数据并在主页上显示

时间:2015-04-26 18:28:19

标签: android

我正在使用“查看全部”按钮在Datapicker。java活动中显示来自数据库的SQL Lite数据,现在我想在家庭活动中显示这些数据(Mainactivity。java)启动应用程序后(不是通过按钮单击)而不是Datapicker.java。这是Datapicker。java

中的代码
         case R.id.btnViewAll:
            Cursor c=db.rawQuery("SELECT * FROM jaffa order by date asc", null);
            if(c.getCount()==0)
            {
                showMessage("Error", "No records found");
                return;
            }
            StringBuffer buffer=new StringBuffer();
            while(c.moveToNext())
            {
                buffer.append("Name: "+c.getString(0)+"\n");
                buffer.append("Occasion: "+c.getString(1)+"\n");
                buffer.append("Date: "+c.getString(2)+"\n"+"\n");

            }
            showMessage("Occasion Details", buffer.toString());
            break;


public void showMessage(String title,String message)
{
    Builder builder=new Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.show();

0 个答案:

没有答案