Hello All,
I am new to android and i am having some difficulties in populating a Grid View with data from SQLite.
I am using Eclipse.
This is my code in the Main class:
And the DBAdpater class follows:
And the imggriditem.xml file for the layout is:
The line
in class GridImages is not working!! 
Please help me with this!! I'm completely new to android and i'm really stuck with this!!
I am new to android and i am having some difficulties in populating a Grid View with data from SQLite.
I am using Eclipse.
This is my code in the Main class:
Code:
public class GridImages extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
populateGridView();
}
public void populateGridView()
{
DBAdapter db = new DBAdapter(this);
GridView gv = (GridView)this.findViewById(R.id.gdImages);
Cursor c = db.getAllDishes();
startManagingCursor(c);
String[] cols = new String[]{"IMAGEPATH"};
int[] names = new int[]{R.id.imgItem};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.imggriditem ,c,cols,names);
gv.setAdapter(adapter);
}
}
And the DBAdpater class follows:
Code:
public class DBAdapter
{
private final Context context;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
db = SQLiteDatabase.openDatabase("/sdcard/gridimages.sqlite", null, SQLiteDatabase.OPEN_READONLY);
}
}
And the imggriditem.xml file for the layout is:
Code:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imgItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
The line
Code:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.imggriditem ,c,cols,names);

Please help me with this!! I'm completely new to android and i'm really stuck with this!!


