Salve amici
allora sono quasi al termine della mia app....ora mi serve solo un aiuto su come popolare la mia listview che ho creato con i dati dal mio db...
io faccio questo metodo nel db:
codice:public ArrayList<Note> GetNotes(String mail){ SQLiteDatabase db = this.getReadableDatabase(); ArrayList<Note> notes = new ArrayList<Note>(); notes.clear(); String sql = "SELECT titolo, colore, data_scadenza FROM ToDoNotes_Notes WHERE email_user = '" + mail + "'"; Cursor cursor = db.rawQuery(sql, null); if(cursor != null || cursor.getCount() != 0){ if(cursor.moveToFirst()){ do{ String titolo = (cursor.getString(cursor.getColumnIndex("titolo"))); String colore =(cursor.getString(cursor.getColumnIndex("colore"))); String data_sca =(cursor.getString(cursor.getColumnIndex("data_scadenza"))); Note n = new Note(titolo,"","",colore,data_sca); notes.add(n); Log.d("tutte le note", n.toString()); } while (cursor.moveToNext()); } } cursor.close(); return notes; }
poi ho creato questo layout xml
1
2<RelativeLayout xmlns:android ="http://schemas.android.com/apk/res/android"
3android:layout_width="match_parent"
4android:layout_height="match_parent"
5android:orientation="horizontal"
6android:padding ="10dp">
7
8<TextView
9android:id="@+id/colorenota"
10android:layout_width="wrap_content"
11android:layout_height="wrap_content"
12android:layout_alignParentLeft="true"
13android:layout_centerVertical="true"/>
14
15
16<TextView
17android:id="@+id/titolo"
18android:layout_width="150dp"
19android:layout_height="wrap_content"
20android:layout_toRightOf="@id/colorenota"
21android:layout_centerVertical="true"/>
22
23<TextView
24android:id="@+id/scadenza"
25android:layout_width="wrap_content"
26android:layout_height="wrap_content"
27android:layout_toRightOf="@id/titolo"
28android:layout_centerVertical="true"/>
29</RelativeLayout>
30
e la mia main activity cosi:
361?xml version="1.0" encoding="utf-8"?>
2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3xmlns:tools="http://schemas.android.com/tools"
4android:layout_width="match_parent"
5android:layout_height="match_parent"
6tools:context=".MainActivity"
7android:background="#D6D6D6">
8
9
10<LinearLayout
11android:layout_width="fill_parent"
12android:layout_height="wrap_content"
13android:layout_alignParentTop="true"
14android:orientation="vertical">
15
16
17<include
18android:id="@+id/toolbar"
19layout="@layout/toolbar"/>
20
21
22<ListView
23xmlns:android ="http://schemas.android.com/apk/res/android"
24xmlns:tools="http://schemas.android.com/tools"
25android:layout_width="match_parent"
26android:layout_height="match_parent"
27android:id="@+id/listview"
28tools:context=".MainActivity">
29
30</ListView>
31
32
33</LinearLayout>
34
35
36</RelativeLayout>
cosa devo fare nella main activity per avere le 3 info che voglio??