SQLite
 sql >> Baza danych >  >> RDS >> SQLite

Jak nadać pozycji zero spinnera odpowiednią wartość?

Pobierasz dane z bazy danych w al ArrayList. Następnie możesz wykonać następujące czynności

al.add(0, "YOUR MESSAGE");    

Dodaje ciąg TWÓJ WIADOMOŚĆ w miejscu 0th indeks.

Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Następnie przekaż listę do arrayadapter

ArrayAdapter<String> aa1 = new ArrayAdapter<String>(
            getApplicationContext(), android.R.layout.simple_spinner_item,
            al);

    spn.setAdapter(aa1);

Proszę sprawdzić ArrayList

EDYTUJ

Oto kod

public void loadtospinner() {

    ArrayList<String> al = new ArrayList<String>();

    Cursor c = SQLcon.readData();
    c.moveToFirst();
    while (!c.isAfterLast()) {

        String name = c.getString(c.getColumnIndex(DBhelper.MEMBER_NAME));
        String calories = c.getString(c
                .getColumnIndex(DBhelper.KEY_CALORIES));

        al.add(name + ", Calories: " + calories);

        c.moveToNext();
    }

    al.add(0, "YOUR MESSAGE");    // do this after while loop and that's it. 


    ArrayAdapter<String> aa1 = new ArrayAdapter<String>(
            getApplicationContext(), android.R.layout.simple_spinner_item,
            al);

    spn.setAdapter(aa1);

    // closing database
    SQLcon.close();

}


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Jak działa SQLite Count()

  2. Jak przetłumaczyć funkcję array_agg PostgreSQL na SQLite?

  3. Dlaczego otrzymuję wyjątek java.lang.IllegalArgumentException:wartość wiązania w indeksie 1 jest w tym przypadku null?

  4. SQLite JSON_REMOVE()

  5. Polecenia SQLite