There is a ListView in YearActivity - the list of months, after clicking on which in another ListMonth I want to display a list of only data from the month for which the choice was made:
lvYear.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { Intent intent = new Intent(YearActivity.this, ListMonth.class); startActivity(intent); } } }); ListMonth:
public class ListMonth extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> ... private static class MySimpleCursor extends CursorLoader { DB db; public MySimpleCursor(Context context, DB db) { super(context); this.db = db; } @Override public Cursor loadInBackground() { Cursor cursor = db.getData(); return cursor; } } There is a database. It has a method where I want to sort the data by month:
public Cursor getData() { selectionArgs = new String[]{"11"}; selection = "month = ?"; orderBy = "day"; return sqLiteDatabase.query(DB_TABLE, null, selection, selectionArgs, null, null, orderBy); } How in selectionArgs to transfer, on what position the user has clicked?
selectionArgs = new String[]{"11"} - like this, for example, only November is displayed.