gridview - Grid view in Android -
hi want display table of data in mobile. in rows , columns trying achive below in getview method, created tablerow , added 3 textview , retruned tablerow. displays first textview added tablerow
can me in new android. need dispaly thsi.
colval11 colval12 colval13 colval21 colval22 colval23
go through below example: hope ..no main.xml
<?xml version="1.0" encoding="utf-8"?> <gridview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnwidth="90dp" android:numcolumns="auto_fit" android:verticalspacing="10dp" android:horizontalspacing="10dp" android:stretchmode="columnwidth" android:gravity="center"/>
//main activity
package com.test2; import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.gridview; import android.widget.toast; import android.widget.adapterview.onitemclicklistener; public class test2 extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.temp); gridview gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new imageadapter(this)); gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(test2.this, "" + position, toast.length_short).show(); } });}
}
///baseadapter
package com.test2; import android.content.context; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.gridview; import android.widget.imageview; public class imageadapter extends baseadapter { private context mcontext; public imageadapter(context c) { mcontext = c; } public int getcount() { return mthumbids.length; } public object getitem(int position) { return null; } public long getitemid(int position) { return 0; } // create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) { imageview imageview; if (convertview == null) { // if it's not recycled, initialize attributes imageview = new imageview(mcontext); imageview.setlayoutparams(new gridview.layoutparams(85, 85)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); } else { imageview = (imageview) convertview; } imageview.setimageresource(mthumbids[position]); return imageview; } // references our images private integer[] mthumbids = { r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7, r.drawable.sample_0, r.drawable.sample_1, r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7, r.drawable.sample_0, r.drawable.sample_1, r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7 }; }
Comments
Post a Comment