PNG image -> SQLite DB -> imageview

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

PNG image -> SQLite DB -> imageview

Postby schrotti08 » Tue Jul 21, 2009 8:43 am

I am bit a newbie in this area ... so it may sound like a basic question to you ... but for me however this poses a huge challenge. Here is what I'd like to do:

1. Write an image file (png) into an SQLite DB (I guess I have to go with BLOB to do this but not sure exactly how)

2. Then pull this PNG image from the DB to show it in a regular listview (regular list adapter) and combine it with corresponding text

So for example, one DB entry would have an image of an apple, the word "apple" as a text to describe the image and a couple of parameter to describe the nutritional value of the apple, like calories, vitamins, and so on.
Another entry would have an orange or a banana ...

Then show all those DB entries in a listview (image + corresponding text elements) to make it look like this:

---------------------------------------------------------
<Apple PNG> Apple, 30 kcal, 3mg vitamin C
---------------------------------------------------------
<Orange PNG> Orange, 45 kcal, 10mg vitamin C
---------------------------------------------------------
and so ......
---------------------------------------------------------

I am aware that I could use a custom list adapter and pull the image from @drawables but the SQLite approach seems more elegant and appropriate to me.

As I am novice I would appreciate a tutorial & sample code that shows how to do this.

Thanks in advance.

Best regards Christian
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Top

Postby padde » Tue Jul 21, 2009 1:01 pm

Are you talking about a local DB on the device or
do you mean a remote DB online?
I am asking because i would like to give some sample code.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby schrotti08 » Tue Jul 21, 2009 1:10 pm

It is a local SQLite DB on the device itself. (At least for the moment). Once I am over this hurdle I would like to connect my application to a webservice then your second option may be relevant for me ...
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Postby padde » Tue Jul 21, 2009 5:10 pm

So here is an example how to store some data (bitmap included) to a local DB
and how to get the data back again.

First the Class that defines a Fruit
Fruit.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.DBtest;
  2.  
  3. import android.graphics.Bitmap;
  4.  
  5. public class Fruit {
  6.     private Bitmap bmp;
  7.     private String name;
  8.     private int kcal;
  9.     private int vitaminc;
  10.  
  11.     public Fruit(Bitmap b, String n, int k, int v) {
  12.         bmp = b;
  13.         name = n;
  14.         kcal = k;
  15.         vitaminc = v;
  16.     }
  17.    
  18.     public Bitmap getBitmap() { return bmp; }
  19.     public String getName() { return name; }
  20.     public int getKcal() { return kcal; }
  21.     public int getVitaminC() { return vitaminc; }
  22. }
  23.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Nothing special here..


Now a Class that helps us handle the database
DBhelper.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.DBtest;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4.  
  5. import android.content.ContentValues;
  6. import android.content.Context;
  7. import android.database.Cursor;
  8. import android.database.SQLException;
  9. import android.database.sqlite.SQLiteDatabase;
  10. import android.database.sqlite.SQLiteOpenHelper;
  11. import android.graphics.Bitmap;
  12. import android.graphics.BitmapFactory;
  13.  
  14. public class DBhelper {
  15.     public static final String KEY_ID = "id";
  16.     public static final String KEY_NAME = "name";
  17.     public static final String KEY_KCAL = "kcal";
  18.     public static final String KEY_VC = "vitaminc";
  19.     public static final String KEY_IMG = "image";
  20.    
  21.     private DatabaseHelper mDbHelper;
  22.     private SQLiteDatabase mDb;
  23.    
  24.     private static final String DATABASE_NAME = "DBtest";
  25.     private static final int DATABASE_VERSION = 1;
  26.    
  27.     private static final String FRUITS_TABLE = "fruits";
  28.  
  29.     private static final String CREATE_FRUITS_TABLE = "create table "+FRUITS_TABLE+" ("
  30.                                          +KEY_ID+" integer primary key autoincrement, "
  31.                                          +KEY_IMG+" blob not null, "
  32.                                          +KEY_NAME+" text not null unique, "
  33.                                          +KEY_KCAL+" integer not null, "
  34.                                          +KEY_VC+" integer not null);";
  35.                                              
  36.     private final Context mCtx;
  37.  
  38.     private static class DatabaseHelper extends SQLiteOpenHelper {
  39.         DatabaseHelper(Context context) {
  40.             super(context, DATABASE_NAME, null, DATABASE_VERSION);
  41.         }
  42.    
  43.         public void onCreate(SQLiteDatabase db) {
  44.             db.execSQL(CREATE_FRUITS_TABLE);
  45.         }
  46.    
  47.         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  48.             db.execSQL("DROP TABLE IF EXISTS "+FRUITS_TABLE);
  49.             onCreate(db);
  50.         }
  51.     }
  52.    
  53.     public void Reset() { mDbHelper.onUpgrade(this.mDb, 1, 1); }
  54.    
  55.     public DBhelper(Context ctx) {
  56.         mCtx = ctx;
  57.         mDbHelper = new DatabaseHelper(mCtx);
  58.     }
  59.    
  60.     public DBhelper open() throws SQLException {
  61.         mDb = mDbHelper.getWritableDatabase();
  62.         return this;
  63.     }
  64.    
  65.     public void close() { mDbHelper.close(); }
  66.  
  67.     public void createFruitEntry(Fruit fruit) {
  68.         ByteArrayOutputStream out = new ByteArrayOutputStream();
  69.         fruit.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out);
  70.         ContentValues cv = new ContentValues();
  71.         cv.put(KEY_IMG, out.toByteArray());            
  72.         cv.put(KEY_NAME, fruit.getName());
  73.         cv.put(KEY_KCAL, fruit.getKcal());
  74.         cv.put(KEY_VC, fruit.getVitaminC());
  75.         mDb.insert(FRUITS_TABLE, null, cv);
  76.     }
  77.    
  78.     public Fruit getFirstFruitFromDB() throws SQLException {
  79.         Cursor cur = mDb.query(true,
  80.                                FRUITS_TABLE,
  81.                                new String[] {KEY_IMG, KEY_NAME, KEY_KCAL, KEY_VC},
  82.                                null, null,null, null, null, null);
  83.         if(cur.moveToFirst()) {
  84.             byte[] blob = cur.getBlob(cur.getColumnIndex(KEY_IMG));
  85.             Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
  86.             String name = cur.getString(cur.getColumnIndex(KEY_NAME));
  87.             int kcal = cur.getInt(cur.getColumnIndex(KEY_KCAL));
  88.             int vc = cur.getInt(cur.getColumnIndex(KEY_VC));
  89.             cur.close();
  90.             return new Fruit(bmp,name,kcal,vc);
  91.         }
  92.         cur.close();
  93.         return null;
  94.     }    
  95. }
  96.  
Parsed in 0.046 seconds, using GeSHi 1.0.8.4

The "magic" happens here in the createFruitEntry and getFirstFruitFromDB methods.
I used a small code version to convert a bitmap to a byte array for storage as blob.. but i doubt that
this is the best or fastest way to do this.

The last Class is the Activity that shows usage of the DBhelper on the basis of an example.
DBtest
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.DBtest;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.BitmapFactory;
  5. import android.os.Bundle;
  6. import android.view.ViewGroup;
  7. import android.widget.ImageView;
  8. import android.widget.LinearLayout;
  9. import android.widget.TextView;
  10.  
  11. public class DBtest extends Activity {
  12.     private DBhelper DbHelper;
  13.        
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.        
  17.         LinearLayout layout = new LinearLayout(this);
  18.         ImageView image = new ImageView(this);
  19.         TextView text = new TextView(this);
  20.        
  21.         DbHelper = new DBhelper(this);
  22.        
  23.         Fruit testFruit = new Fruit(
  24.                 BitmapFactory.decodeResource(getResources(), R.drawable.icon),
  25.                 "Icon", 100, 0);
  26.  
  27.         DbHelper.open();
  28.         DbHelper.createFruitEntry(testFruit);
  29.         DbHelper.close();
  30.        
  31.         testFruit = null;
  32.        
  33.         DbHelper.open();
  34.         testFruit = DbHelper.getFirstFruitFromDB();
  35.         DbHelper.close();
  36.        
  37.         image.setImageBitmap(testFruit.getBitmap());
  38.         text.setText("Name: "+testFruit.getName()+", "
  39.                 +testFruit.getKcal()+"kcal, "
  40.                 +testFruit.getVitaminC()+"mg Vitamin C");
  41.        
  42.         ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
  43.                                         LinearLayout.LayoutParams.WRAP_CONTENT,
  44.                                         LinearLayout.LayoutParams.WRAP_CONTENT);
  45.        
  46.         setContentView(layout);
  47.         addContentView(image, params);
  48.         addContentView(text, params);
  49.     }
  50. }
  51.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4

Here again nothing special..


Later.. with a remote DB and a webservice i would suggest usage of Servlets and Tomcat or Jetty as
Servlet-Container.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby schrotti08 » Tue Jul 21, 2009 8:08 pm

Wow - great. Let me try this out and see if I can get it up and running ... will let you know in case of success or non-success ;-)
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Postby padde » Fri Jul 24, 2009 12:18 am

I found a great tutorial on another site.. it covers some problems that may appear when your app is in the next stage (remote DB + webservice).

http://developerlife.com/tutorials/?p=289
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Postby schrotti08 » Tue Jul 28, 2009 9:38 am

That tutorial does look interesting. Very good input for the next stage!
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Thx!

Postby cykane » Wed Aug 05, 2009 2:24 pm

Padde you are the man! Thx!
cykane
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 05, 2009 2:22 pm

Postby schrotti08 » Mon Aug 31, 2009 2:43 pm

Padde, thanks again for this perfectly working code to extract a PNG image from an SQL database.

Maybe I am asking too much of you ... but I cannot move on at the moment and I am stuck here. I would like to expand your code to make it work with a cursor adapter.

Here is the code I currently have to bind only strings from SQL DB to a simple cursor adapter. How can I expand this to make it work with your bit more complex structure using a bitmap, integer and string all coming from SQL DB. My goal is just to populate a listview (image left, then string and then integer values).

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabelle_listview);

entries = new DBHelper(this);
Cursor cursor = getEntries();
showEntries(cursor);
}

private static String[] FROM = {FRUIT, CALORIES, VITC, VITA, VITB, VITD, VITE, _ID};
private static String ORDER_BY = _ID + " ASC";

private Cursor getEntries() {
//Perform a managed query. The Activity will handle closing
//and re-querying the cursor when needed.
SQLiteDatabase db = entries.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME_FRUITS, FROM, null, null, null, null, null);

startManagingCursor(cursor);
return cursor;
}

private static int[] TO = { R.id.fruit, R.id.calories, R.id.vitc, R.id.vita, R.id.vitb, R.id.vitd, R.id.vite};

private void showEntries(Cursor cursor) {

ListView v = getListView(); // set up item selection listener
v.setOnItemSelectedListener( this ); // see OnItemSelectedListener methods below

// Set up data binding
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.fruit_item, cursor, FROM, TO);
setListAdapter(adapter);

}
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Postby Profete162 » Mon Dec 28, 2009 9:06 am

The answer to your last question would be very interesting for me.

I am looking for such a method, and i'm fed up to create custom adapters.

I hope an universal solution for icon + string would exist!

(sorry for my english)
Profete162
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Nov 27, 2009 6:07 pm

Great Help...!!! Thanks

Postby pria » Fri Mar 12, 2010 1:29 pm

Hey Padde...Gr8 example...Thnx a lot!
pria
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Mar 02, 2010 1:37 pm
Location: Pune

store images in sqlite database and show that in listview

Postby hany » Wed Apr 28, 2010 7:01 am

Thank you for this example .

I am new to android . how to store list of fruits and names and how to retrive that data and how to show that data in listview . please send me a sample code .

Thank you
hany
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Mar 13, 2010 6:35 am

Postby padde » Wed Apr 28, 2010 11:19 am

To cover an association between a name and multiple fruits you should use another table.
For example FavoriteFruit with a column for the name and a column for an ID that is cross referencing to one fruit
in the fruit table. That way you can get all favorite fruits from a particular person.
Presenting the data in a listview is a whole nother story.

I'm willing to extend the fruit example to cover all this but i won't find the time till weekend to do this.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

store images in sqlite database and show that in listview

Postby hany » Wed Apr 28, 2010 12:09 pm

Thanks for ur reply .

I am saying only store the no of images and its names into database and retrive the data from database and show that data into listview (image and name).


Thank you .
hany
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Mar 13, 2010 6:35 am

Postby padde » Wed Apr 28, 2010 6:46 pm

I found some minutes thanks to a canceled meeting :D
I changed the sample to a ListActivity and show a sample of presenting
the data from the database in a list.
If i understand it right thats what you want.

First the class representing a fruit:
Fruit.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.fruitsdbsample;
  2.  
  3. import android.graphics.Bitmap;
  4.  
  5. public class Fruit {
  6.     private Bitmap bmp;
  7.     private String name;
  8.     private int kcal;
  9.     private int vitaminc;
  10.  
  11.     public Fruit(Bitmap b, String n, int k, int v) {
  12.         bmp = b;
  13.         name = n;
  14.         kcal = k;
  15.         vitaminc = v;
  16.     }
  17.    
  18.     public Bitmap getBitmap() { return bmp; }
  19.     public String getName() { return name; }
  20.     public int getKcal() { return kcal; }
  21.     public int getVitaminC() { return vitaminc; }
  22. }
  23.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

Nothing changed here...

Next is the class helping us handling the DB:
DBhelper.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.fruitsdbsample;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4.  
  5. import android.content.ContentValues;
  6. import android.content.Context;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.database.sqlite.SQLiteOpenHelper;
  9. import android.graphics.Bitmap;
  10. import android.provider.BaseColumns;
  11.  
  12. public class DBhelper {
  13.     public static final String KEY_ID = BaseColumns._ID;
  14.     public static final String KEY_NAME = "name";
  15.     public static final String KEY_KCAL = "kcal";
  16.     public static final String KEY_VC = "vitaminc";
  17.     public static final String KEY_IMG = "image";
  18.    
  19.     private DatabaseHelper mDbHelper;
  20.     private SQLiteDatabase mDb;
  21.    
  22.     private static final String DATABASE_NAME = "FruitDB";
  23.     private static final int DATABASE_VERSION = 1;
  24.    
  25.     public static final String FRUITS_TABLE = "fruits";
  26.  
  27.     private static final String CREATE_FRUITS_TABLE = "create table "+FRUITS_TABLE+" ("
  28.                                          +KEY_ID+" integer primary key autoincrement, "
  29.                                          +KEY_IMG+" blob not null, "
  30.                                          +KEY_NAME+" text not null unique, "
  31.                                          +KEY_KCAL+" integer not null, "
  32.                                          +KEY_VC+" integer not null);";
  33.                                              
  34.     private final Context mCtx;
  35.     private boolean opened = false;
  36.    
  37.  
  38.     private static class DatabaseHelper extends SQLiteOpenHelper {
  39.         DatabaseHelper(Context context) {
  40.             super(context, DATABASE_NAME, null, DATABASE_VERSION);
  41.         }
  42.    
  43.         public void onCreate(SQLiteDatabase db) {
  44.             db.execSQL(CREATE_FRUITS_TABLE);
  45.         }
  46.    
  47.         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  48.             db.execSQL("DROP TABLE IF EXISTS "+FRUITS_TABLE);
  49.             onCreate(db);
  50.         }
  51.     }
  52.    
  53.     public void Reset() {
  54.         openDB();
  55.         mDbHelper.onUpgrade(this.mDb, 1, 1);
  56.         closeDB();
  57.     }
  58.    
  59.     public DBhelper(Context ctx) {
  60.         mCtx = ctx;
  61.         mDbHelper = new DatabaseHelper(mCtx);
  62.     }
  63.    
  64.     private SQLiteDatabase openDB() {
  65.         if(!opened)
  66.             mDb = mDbHelper.getWritableDatabase();
  67.         opened = true;
  68.         return mDb;
  69.     }
  70.    
  71.     public SQLiteDatabase getHandle() { return openDB(); }
  72.    
  73.     private void closeDB() {
  74.         if(opened)
  75.             mDbHelper.close();
  76.         opened = false;
  77.     }
  78.  
  79.     public void createFruitEntry(Fruit fruit) {
  80.         openDB();
  81.         ByteArrayOutputStream out = new ByteArrayOutputStream();
  82.         fruit.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out);
  83.         ContentValues cv = new ContentValues();
  84.         cv.put(KEY_IMG, out.toByteArray());            
  85.         cv.put(KEY_NAME, fruit.getName());
  86.         cv.put(KEY_KCAL, fruit.getKcal());
  87.         cv.put(KEY_VC, fruit.getVitaminC());
  88.         mDb.insert(FRUITS_TABLE, null, cv);
  89.         closeDB();
  90.     }
  91. }
  92.  
Parsed in 0.058 seconds, using GeSHi 1.0.8.4

Nothing essential changed here...

Following class is new and defines how to bind the data to the Views.
Out of the box SimpleCursorAdapter supports TextView and ImageView but
images have to be in form of a image ressource or a URI. Therefore we need
this class to override default binding and/or define how to bind to other view types.
FruitViewBinder.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.fruitsdbsample;
  2.  
  3. import android.database.Cursor;
  4. import android.graphics.BitmapFactory;
  5. import android.view.View;
  6. import android.widget.ImageView;
  7. import android.widget.RatingBar;
  8. import android.widget.SimpleCursorAdapter;
  9.  
  10. public class FruitViewBinder implements SimpleCursorAdapter.ViewBinder {
  11.         public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
  12.                
  13.                 if(view instanceof ImageView) {
  14.                         ImageView iv = (ImageView) view;
  15.                         byte[] img = cursor.getBlob(columnIndex);
  16.                         iv.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
  17.                         return true;
  18.                 }
  19.  
  20.                 if(view instanceof RatingBar) {
  21.                         RatingBar rb = (RatingBar) view;
  22.                         int kcal = cursor.getInt(cursor.getColumnIndex(DBhelper.KEY_KCAL));
  23.                         int vitc = cursor.getInt(cursor.getColumnIndex(DBhelper.KEY_VC));
  24.                         rb.setRating((float) (kcal * ((float) vitc/1000.0)));
  25.                         return true;
  26.                 }
  27.                
  28.                 return false;
  29.         }
  30. }
  31.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Last class is the ListActivity that implements the example
FruitDBSample
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.padde.fruitsdbsample;
  2.  
  3. import android.app.ListActivity;
  4. import android.database.Cursor;
  5. import android.graphics.Bitmap;
  6. import android.graphics.BitmapFactory;
  7. import android.os.Bundle;
  8. import android.widget.SimpleCursorAdapter;
  9.  
  10. public class FruitsDBSample extends ListActivity {
  11.     private DBhelper mDB;
  12.        
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.              
  16.         mDB = new DBhelper(this);
  17.        
  18.         mDB.Reset();
  19.        
  20.         Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
  21.        
  22.         mDB.createFruitEntry(new Fruit(img, "Banane",   92, 10));
  23.         mDB.createFruitEntry(new Fruit(img, "Kiwi",     56, 71));
  24.         mDB.createFruitEntry(new Fruit(img, "Pfirsich", 41, 10));
  25.         mDB.createFruitEntry(new Fruit(img, "Zitrone",  40, 51));
  26.        
  27.         String[] columns = {mDB.KEY_ID, mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_KCAL, mDB.KEY_VC};
  28.         String   table   = mDB.FRUITS_TABLE;
  29.        
  30.         Cursor c = mDB.getHandle().query(table, columns, null, null, null, null, null);
  31.  
  32.         startManagingCursor(c);
  33.        
  34.         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
  35.                 R.layout.fruitlist,
  36.                 c,
  37.                 new String[] {mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_KCAL, mDB.KEY_VC},
  38.                 new int[] {R.id.img, R.id.txt, R.id.rating});
  39.        
  40.         adapter.setViewBinder(new FruitViewBinder());
  41.  
  42.         setListAdapter(adapter);
  43.     }
  44. }
  45.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


And last but not least the xml that defines the layout of a row in the final list
fruitlist.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="wrap_content">
  6.    
  7.     <ImageView
  8.        android:id = "@+id/img"
  9.        android:layout_width = "wrap_content"
  10.        android:layout_height = "wrap_content"
  11.        android:layout_alignParentLeft = "true">
  12.     </ImageView>
  13.    
  14.     <TextView
  15.        android:id = "@+id/txt"
  16.        android:layout_width = "wrap_content"
  17.        android:layout_height = "wrap_content"
  18.        android:layout_centerVertical = "true"
  19.        android:layout_toRightOf = "@id/img">
  20.     </TextView>
  21.    
  22.     <RatingBar
  23.        style="?android:attr/ratingBarStyleSmall"    
  24.        android:id = "@+id/rating"
  25.        android:numStars = "5"
  26.        android:stepSize = "0.5"
  27.        android:layout_width = "wrap_content"
  28.        android:layout_height = "wrap_content"
  29.        android:layout_alignParentRight = "true"
  30.        android:layout_centerVertical = "true"
  31.        android:layout_marginRight = "5px">
  32.     </RatingBar>
  33.    
  34.     <TextView
  35.        android:text = "Healthindex: "
  36.        android:layout_width = "wrap_content"
  37.        android:layout_height = "wrap_content"
  38.        android:layout_centerVertical = "true"
  39.        android:layout_toLeftOf = "@id/rating">
  40.     </TextView>
  41.    
  42. </RelativeLayout>
  43.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


This is all pretty straight forward so no further explanation at this point.. but should something
remain unclear feel free to ask.

Greets Padde

--- Edit ---
And this is how it looks like.

Image
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top
Next

Return to Networking & Database Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests