I can show the list of images out but the the data. I took it from an example online. This is my DBAdapter.java
public class DBAdapter
{
//values for the login table
public static final String KEY_ROWID = "_id";
public static final String KEY_USER = "user";
public static final String KEY_PASSWORD = "pass";
public static final String KEY_NUMBER ="no";
//Values for the entry table
public static String KEY_ROWID2 = "_id2";
public static String KEY_TITLE = "title";
public static String KEY_ENTRY = "entry";
public static String KEY_MOOD = "mood";
public static String KEY_DATE = "date";
public static String KEY_TIME = "time";
private static final String TAG = "DBAdapter";
//declare Database name, tables names
private static final String DATABASE_NAME = "Database3";
private static final String DATABASE_TABLE = "Login";
private static final String DATABASE_TABLE_2 = "Entry";
private static final int DATABASE_VERSION = 1;
//declares the rules for the database tables
private static final String DATABASE_CREATE =
"create table login (_id integer primary key autoincrement, "
+ "user text not null, pass text not null,"
+ " no integer not null);";
private static final String DATABASE_CREATE_2 =
"create table entry (_id2 integer primary key autoincrement, "
+ "title text,entry text, mood text not null, date text not null, "
+ "time text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
//Create the tables with the rules we set.
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
db.execSQL(DATABASE_CREATE_2);
}
//OnUpgrade is only for use when u changed the database's version to 2 etc.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
//Method for inserting login details, can be used in other java files when DBAdapter is
//declared in the java file. e.g. DBAdapter db = new DBAdapter(this);
public long insertLogin(String user, String pass, String no)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_USER, user);
initialValues.put(KEY_PASSWORD, pass);
initialValues.put(KEY_NUMBER, no);
return db.insert(DATABASE_TABLE, null, initialValues);
}
public long insertEntry(String title, String entry, String mood, String date, String time)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_ENTRY, entry);
initialValues.put(KEY_MOOD, mood);
initialValues.put(KEY_DATE, date);
initialValues.put(KEY_TIME, time);
return db.insert(DATABASE_TABLE_2, null, initialValues);
}
//---deletes a particular title---
public boolean deleteLogin(long rowId)
{
return db.delete(DATABASE_TABLE, KEY_ROWID +
"=" + rowId, null) > 0;
}
public boolean deleteEntry(long rowId2)
{
return db.delete(DATABASE_TABLE_2, KEY_ROWID2 +
"=" + rowId2, null) > 0;
}
//method for retrieving all the inputs from database
public Cursor getAllLogin()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_USER,
KEY_PASSWORD,
KEY_NUMBER,},
null,
null,
null,
null,
null,
null);
}
/*public Cursor getAllEntry() { return db.query(DATABASE_TABLE_2, new String[] { KEY_ROWID2, KEY_TITLE, KEY_ENTRY, KEY_MOOD, KEY_DATE, KEY_TIME}, null, null, null, null, null, null); }*/
public List<String> getAllEntry() {
ArrayList<String> entry = new ArrayList<String>();
try{
Cursor c = db.query("Entry", new String[] { "KEY_ROWID2",
"KEY_TITLE", "KEY_ENTRY", "KEY_MOOD", "KEY_DATE", "KEY_TIME" },
null, null, null, null, null, null);
int numRows = c.getCount();
c.isFirst();
if (c != null)
{
for (int i = 0; i < numRows; ++i)
{
DBAdapter entry1 = new DBAdapter(context);
entry1.KEY_ROWID2 = c.getString(0);
entry1.KEY_TITLE = c.getString(1);
entry1.KEY_ENTRY = c.getString(2);
entry1.KEY_MOOD = c.getString(3);
entry1.KEY_DATE = c.getString(4);
entry1.KEY_TIME= c.getString(5);
//entry.add(entry1);
c.moveToNext();
}
}
}catch (SQLException e){
Log.e("DBAdapter", e.toString());
}
return entry;
}
//---retrieves a particular title---
public Cursor getLogin(long rowId) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_USER,
KEY_PASSWORD,
KEY_NUMBER},
KEY_ROWID + "=" + rowId,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public Cursor getEntry(long rowId2) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_TABLE_2, new String[] {
KEY_ROWID2,
KEY_TITLE,
KEY_ENTRY,
KEY_MOOD,
KEY_DATE,
KEY_TIME},
KEY_ROWID2 + "=" + rowId2,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
//---updates a title---
public boolean updateLogin(long rowId, String user,
String pass, String no)
{
ContentValues args = new ContentValues();
args.put(KEY_USER, user);
args.put(KEY_PASSWORD, pass);
args.put(KEY_NUMBER, no);
return db.update(DATABASE_TABLE, args,
KEY_ROWID + "=" + rowId, null) > 0;
}
public boolean updateEntry(long rowId,String title, String entry,
String mood, String date, String time)
{
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
args.put(KEY_ENTRY, entry);
args.put(KEY_MOOD, mood);
args.put(KEY_DATE, date);
args.put(KEY_TIME, time);
return db.update(DATABASE_TABLE_2, args,
KEY_ROWID2 + "=" + rowId, null) > 0;
}
}
And, this is my List_View.java
public class List_View extends ListActivity {
private DBAdapter db;
private TextView toptext; private TextView bottomtext; private ListView lv;
public void onCreate(Bundle savedInstanceState) { try{
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
db = new DBAdapter(this);
toptext = (TextView) findViewById (R.id.toptext);
bottomtext = (TextView) findViewById (R.id.bottomtext);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> item;
for (int i = 0; i < 31; i++) {
item = new HashMap<String, String>();
item.put("Date:", "Saved Date" );
item.put("Title:", "Saved Title" );
list.add(item);
}
SimpleAdapter notes = new SimpleAdapter(this, list, R.layout.view_list,
new String[] { "date", "title" },
new int[] {R.id.toptext, R.id.bottomtext });
setListAdapter(notes);
} catch(Throwable e){
Log.e("DBAdapter",e.toString());
} }
}
I know that I shouldn't put Hashmap, but what should I change it to for my ListView to work? I've need to show 2 textviews beside the image and the data is taked from my database which was stored.