i am trying to populate a listview with a custom layout with two strings from a database but am experiencing some difficulties. I have tried many methods but none has worked. I hope someone can give me a better solution. Please help me with the custom layout too.
here is the constructor for the database
public class Vault {
public Vault() //a constructor is created for the creation of the database
{
}
public static abstract class noteInfo implements BaseColumns // a table is then created
{
public static final String USER_NAME = "user_name";
public static final String NOTE = "note";
public static final String TIMESTAMP = "timestamp";
public static final String DATABASE_NAME = "vault";
public static final String TABLE_NAME = "note_cabinet";
}
}
here is the the adapter for the databse public class noteOperations extends SQLiteOpenHelper { public static final int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE " + noteInfo.TABLE_NAME + "(" + noteInfo.NOTE+ " TEXT," + noteInfo.TIMESTAMP + " TEXT," + noteInfo.USER_NAME + " TEXT);";
public noteOperations(Context context) {
super(context, noteInfo.DATABASE_NAME, null, database_version);
Log.d("Note operations", "Database created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_QUERY);
Log.d("Note operations", "Table created");
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void putInformation(noteOperations no, String note, String timestamp, String user)
{
SQLiteDatabase SQ = no.getReadableDatabase();
ContentValues cv = new ContentValues();
cv.put(noteInfo.NOTE, note);
cv.put(noteInfo.TIMESTAMP, timestamp);
cv.put(noteInfo.USER_NAME, user);
SQ.insert(noteInfo.TABLE_NAME, null, cv);
Log.d("Note operations", "One note inserted");
}
public Cursor getInformation(noteOperations no)
{
SQLiteDatabase SQ = no.getReadableDatabase();
String[] columns = {noteInfo.NOTE, noteInfo.TIMESTAMP};
Cursor CR = SQ.query(noteInfo.TABLE_NAME, columns, null, null, null, null, null);
Log.d("Note operations", "Table combed");
return CR;
}
public void deleteUser(noteOperations no, String user_name)
{
String selection = noteInfo.USER_NAME + " LIKE ? AND " + noteInfo.NOTE + " LIKE ?" + noteInfo.TIMESTAMP + " LIKE ?";
String args[] = {user_name};
SQLiteDatabase SQ = no.getWritableDatabase();
SQ.delete(noteInfo.TABLE_NAME, selection, args);
Log.d("Databsse operations", "User deleted");
}
public Cursor getallrows(noteOperations no)
{
SQLiteDatabase SQ = no.getReadableDatabase();
String[] columns = {noteInfo.NOTE, noteInfo.TIMESTAMP};
Cursor CR = SQ.query(noteInfo.TABLE_NAME, columns, null, null, null, null, null, null);
if (CR != null)
{
CR.moveToFirst();
}
return CR;
}
}
here is the xml of the custom layout for the listview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bubble_drawable" >
<TextView
android:id="@+id/noteView_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="4dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="@+id/timestampView_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/noteView_layout"
android:padding="3dp"
android:text="TextView"
android:textColor="#ffffff"
android:textStyle="bold" />
</RelativeLayout>
Aucun commentaire:
Enregistrer un commentaire