This is my xml file.The textview is used for layout heading.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:removed="@color/grey"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.paul.household.iddataviewlayout" >
<textview>
android:id="@+id/txtvwtitle"
style="@style/CustomShortTitle"
android:layout_marginTop="1dip"
android:text="@string/vw_head"
android:textAppearance="?android:attr/textAppearanceMedium" />
<gridview>
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="@+id/txtvwtitle"
android:layout_below="@+id/txtvwtitle"
android:layout_marginTop="20dp"
android:removed="#000000"
android:fastScrollAlwaysVisible="true"
android:fastScrollEnabled="true"
android:numColumns="7"
android:columnWidth="300dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:scrollbars="horizontal">
This is my java code
GridView gridView;
final Databasehelper dtbase = new Databasehelper(IDdataview.this);
protected void onCreate(Bundle savedinstanceState) {
super.onCreate(savedinstanceState);
setContentView(R.layout.iddataviewlayout);
gridView = (GridView) findViewById(R.id.gridView1);
getdata();
}
public void getdata() {
final ArrayList<string> list;
final ArrayAdapter<string> adapter;
list = new ArrayList<string>();
adapter = new ArrayAdapter<string>(getApplicationContext(),
android.R.layout.simple_gallery_item, list);
adapter.setDropDownViewResource(R.layout.iddataviewlayout);
String wilaya, moughataa, commune, locality, lname, fname, hhno;
wilaya = "";
moughataa = "";
commune = "";
locality = "";
lname = "";
fname = "";
hhno = "";
dtbase.openDataBase();
String query = "select IDMaster.HHFname,IDMaster.HHLname,IDMaster.HouseNo,IDMaster.LocCode,WilayaMast.WName,MoughataaMast.MName,CommuneMast.CName from IDMaster,WilayaMast,MoughataaMast,CommuneMast where IDMaster.WCode=WilayaMast.WCode and IDMaster.MCode=MoughataaMast.MCode and IDMaster.CCode=CommuneMast.CCode";
Cursor c = dtbase.viewData(query);
if (c.moveToFirst()) {
do {
wilaya = c.getString(c.getColumnIndex("WName"));
moughataa = c.getString(c.getColumnIndex("MName"));
commune = c.getString(c.getColumnIndex("CName"));
locality = c.getString(c.getColumnIndex("LocCode"));
fname = c.getString(c.getColumnIndex("HHFname"));
lname = c.getString(c.getColumnIndex("HHLname"));
hhno = c.getString(c.getColumnIndex("HouseNo"));
// add in to array list
list.add(wilaya);
list.add(moughataa);
list.add(commune);
list.add(locality);
list.add(lname);
list.add(fname);
list.add(hhno);
gridView.setAdapter(adapter);
} while (c.moveToNext());// Move the cursor to the next row.
}
}