samedi 19 décembre 2015

How to retrieve data based on two conditions given?

In MainActivity, I want the listView display the data with a specific month.

 public void BuildList()
    {
        sqlcon.open(); // object of InfoAPI
        Calendar cal = Calendar.getInstance();
        int month = cal.get(Calendar.MONTH)+1;
        Toast.makeText(getApplicationContext(),month+"",Toast.LENGTH_LONG).show();
        Cursor cursor1=sqlcon.readData(month);
        String[] columns=new String[]{
        MyDatabaseHelper.Date,MyDatabaseHelper.TimeIn_Info,MyDatabaseHelper.TimeOut_Info
        };

        int[] to=new int[]
         {
           R.id.date,R.id.timeIn,R.id.timeOut
         };

        dataAdapter = new SimpleCursorAdapter(this, R.layout.retrieve_data,
                cursor1,
                columns,
                to,
                0);

        dataAdapter.setViewBinder(new ViewBinder());
        listView.setAdapter(dataAdapter);
    }

}

InfoAPI

public Cursor readData(int m)
    {
        Cursor c=database.rawQuery(" SELECT _id, Date,Weather,Status, TimeIn_Info, TimeOut_Info FROM " + MyDatabaseHelper.TABLE_INFO + 
                " WHERE Name = ? and strftime('%m',Date)= ?", 
                new String[]{"LCV"}, new String[]{String.valueOf(m)},null);

        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }

Error

 Error:(54, 26) error: no suitable method found for rawQuery(String,String[],String[],<null>)
    method SQLiteDatabase.rawQuery(String,String[]) is not applicable
    (actual and formal argument lists differ in length)
    method SQLiteDatabase.rawQuery(String,String[],CancellationSignal) is not applicable
    (actual and formal argument lists differ in length)

Error:(106, 30) error: method readData in class InfoAPI cannot be applied to given types;
required: int
found: no arguments
reason: actual and formal argument lists differ in length

I get a little bit confused in rawQuery. What is the correct way to write in order to retrieve the data based on two conditions ?

Aucun commentaire:

Enregistrer un commentaire