java – Why only the first element of roulette is happening in Android SQLite?


I am developing a utility bill manager where the customer can add expenses. Expense categories are loaded from the SQLite database to the cursor. The following is the code for that

    public ArrayList getAllthePayableCats() {
    ArrayList payableCatsList = new ArrayList();
    SQLiteDatabase db = this.getReadableDatabase();
    payableCatsList.clear();
    Cursor cursor = db.rawQuery("Select * from OutgoingCategories", null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()){
        Category category = cursorToCategory(cursor);
        payableCatsList.add(category);
        cursor.moveToNext();
    }
        cursor.close();

    return payableCatsList;
}

private Category cursorToCategory(Cursor cursor) {
    Category category = new Category();
    category.setCatID(cursor.getInt(0));
    category.setName(cursor.getString(1));
    return category;
}

Separately, the Category class is created where the setCatID () and SetName () methods are.

The following function loads the data from the Arraylist spinner, whose type is category.

   private void loadSpinnerData() {
    // Spinner Drop down elements
    ArrayList payableCatsList = db.getAllthePayableCats();
    // Creating adapter for spinner
    ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, payableCatsList);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    s.setAdapter(dataAdapter);
}

The function is called inside onCreate ().

Below is how to select the current selected cursor item

    final Category selectedCat = (Category) s.getSelectedItem();
    final int catID = selectedCat.getCatID(); 

here is the name of the roulette defined in the class.

But when the user tries to make an expense, the spinner can see all the articles, but only the first element of the spinner is passed to the SQLite database. What is that problem and how to solve it? A lot of help