I'm working on Android Studio.I have a problem with displaying data from SQLite database on my ListView. Here is a method to take data from SQLite(it works well,checked)
public List<Terminy> getAllItems(){
List<Terminy> itemList = new ArrayList<Terminy>();
String selectQuery = "SELECT id,data FROM Terminy WHERE Wolny = 1";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
Terminy termin = new Terminy();
termin.setId2(Integer.parseInt(cursor.getString(0)));
termin.setData(cursor.getString(1));
itemList.add(termin);
}while(cursor.moveToNext());
}
cursor.close();
return itemList;
}
And there is method to put data into ListView
public void ButtonLista(View v)
{
ArrayAdapter<Terminy> adapter;
ArrayList<Terminy> lista;
DatabaseHelper helper = new DatabaseHelper(this);
ListView listView = (ListView) findViewById(R.id.listView);
lista = new ArrayList<>(helper.getAllItems());
adapter = new ArrayAdapter<Terminy>(this,R.layout.activity_panel_uzytkownik, lista);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
LogCat Error
com.example.czou.proojekt E/ArrayAdapter: You must supply a resource ID for a TextView com.example.czou.proojekt D/AndroidRuntime: Shutting down VM com.example.czou.proojekt W/art: Suspending all threads took: 02-08 17:47:59.352 1779-1779/com.example.czou.proojekt E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.czou.proojekt, PID: 1779 java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
Could some one help me ? I have read many tutorials so far and still don't know how to solve my problem :(