There is a code:

DB = new DataBase(getActivity()); DB.open(); cursor = DB.getPositions(); scAdapter = new SimpleCursorAdapter(getActivity(), R.layout.simple_item, cursor, new String[] {DataBase.Name}, new int[] {android.R.id.text1}, 0) 

Part of the DB:

 Cursor getPositions() { return mDB.rawQuery("SELECT * FROM "+ TABLE, null); } 

How to declare scAdapter in the string new String [] {DataBase.Name} to make it read only the first line with _id = 0? Roughly speaking, it is necessary to read not one column, but several, but only the first lines.
The number of columns is unknown in advance.

  • there is such a WHERE statement in the SQL language. Using it, you can specify the conditions for getting into the selection for the query: "SELECT * FROM " + TABLE + " WHERE _id = 0" - get all the columns of the table whose _id = 0 column. - pavlofff
  • Thanks for the comment, I didn’t have time to write an answer for you. - Antonem

1 answer 1

I apologize for the incorrect question, the essence of the question was how to specify the names of the columns in the adapter, which are periodically added in the form of P1, P2, etc. DB.java

 Cursor getPositions() { return mDB.rawQuery("SELECT * FROM "+ TABLE + " WHERE _id = 0", null); } 

Fragment.java

  cursor = DB.getPositions(); String[] from = new String[cursor.getColumnCount()]; // создаём массив, размерность которого равна количеству столбцов. for (int i = 0; i < cursor.getColumnCount(); i++) { from [i] = "P" + i; // в массив заносим названия столбцов, получается P1, P2, P3 и т.д. } scAdapter = new SimpleCursorAdapter(getActivity(), R.layout.s.imple_item, cursor, from, new int[] {android.R.id.text1}, 0); //объявляем адаптер и вносим туда известные нам названия столбцов.