custom adapter for gridview in android -


Getting data from im dB and is shown in a gridview OK But I'll text displayed.When down I need to put different buttons. I click the button., I have taken some stuff. Here's how I got the data from DB. How can I do this?

My code has been used by the customList adapter for

  increases the public class homepage activity {Private array list & lt; Single Element Details & gt; AllElementDetails = New ArrayList & lt; SingleElementDetails & gt; (); DBAdapter db = new DBAdapter (this); String category, description; String data; String data 1; Gridview Gridviewview; Button menu; Crate on Public Zero (Bundle Saved Instantstate) {Super. Secret (Saved Instantstate); SetContentView (R.layout.homepage); Menu = (button) findViewById (R.id.menus); menu.setOnClickListener (New OnClickListener () {public void onClick (View v) {gridview = (GridView) findViewById (R.id.gridview); allElementDetails.clear (); db.open (); long id; // id = db1.insertTitle1 (category, description r_photo); cursor = db.getAllTitles1 (); while (cursor.moveToNext ()) {SingleElementDetails single = new SingleElementDetails (); single.setCateogry (cursor.getString (1)); single. setDescription (cursor.getString (2)); single.setImage (cursor.getBlob (3)); allElementDetails.add (single);} db.close (); CustomListAdapter adapter = new CustomListAdapter (HomePage.this, allElementDetails); Gridview .setAdapter (adapter);}}); }   

}

My customListAdapter ..

  import java.io.biteArrayInputStream; Import java.util.ArrayList; Import android.content.Context; Import Android.graphics. Bitmap; Import and roid.graphics.BitmapFactory; Import android.view.LayoutInflater; Import android.view.View; Import android.view.ViewGroup; Import android.widget.BaseAdapter; Import android.widget.ImageView; Import android.widget.TextView; Public Class Customlist Adapter Bidder (Private Arrayist & lt; Single Element Details & gt; AllElementDetails; Private layoutInflator aminflator; Public CastelList Adapter (Reference Reference, Arrayist & lt; SingleAlement Details & gt; Results) {allElementDetails = Results; MInflater = layoutInflator. From (context); } Public int getCount () return {allElementDetails.size ()}} public object getItem (integer position) {allElementDetails.get (status); } Public ITMID in the long run (status of return) {Return Status; } View public viewView (int position, seeviewview, ViewGroup parent) {convertView = mInflater.inflate (R.layout.listview1, null); ImageView imageview = (ImageView) Convert View.findViewById (R.id.image); Textview Textview = (TextView) Convertview.FindVibeID (RIDCCT); TextView textview1 = (TextView) convertView.findViewById (R.id.description_entry); Textview.setText (allElementDetails.get (status) .getCategory ()); Textview1.setText (allElementDetails.get (status) .getDescription ()); Byte [] byteimage = allElementDetails.get (status) .getImage (); Bytereinputstream imagestream = new bytereinputstream (biometimate); Bitmapfile Option Option = New Bitmap Feature. Option (); Op.inSampleSize = 12; Bitmap theImage = BitmapFactory.decodeStream (imagestream, blank, op); Imageview.setImageBitmap (theImage); Return Convertview; }   

}

Instead of using CustomListAdapter, you will create extends its own adapter BaseAdapter, your TextView to create a layout for each grid item (extension LinearLayout) in this class then a button

Nice Tut.



Comments