After you retrieve all the records, initialize an adapter and set it to the
list view.

For this you will have to save the records you read from your table, else
you can also use a Cursor adapter and set it to the list view.
Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com



On Fri, Nov 26, 2010 at 11:35 AM, pramod.deore <[email protected]>wrote:

> Hi, I have a table which contain 4columns. I can read these columns
> from database. Now I want to show these columns to listview. How to
> this? I want that list consist of 4 columns as they are present into
> table.
>
> Here is my code:
>
> public class ToDo extends Activity
> {
>        private final String SAMPLE_DBNAME = "HomeAutoDataBase";
>        SQLiteDatabase sampleDB = null;
>        int rid,sid;
>        String roomName,switchName;
>    /** Called when the activity is first created. */
>    @Override
>    public void onCreate(Bundle savedInstanceState)
>    {
>        super.onCreate(savedInstanceState);
>        readDataFromDatabase();
>
>    }
>    public void readDataFromDatabase()
>    {
>         try
>         {
>                sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
> MODE_PRIVATE, null);
>                Cursor c = sampleDB.rawQuery ("SELECT * FROM SwitchTable
> ORDER BY RoomID",null);
>
>                int count = c.getCount();
>                System.out.println ("Total number of records are"+count);
>                if (c != null )
>                {
>                        if  (c.moveToFirst())
>                        {
>                                do
>                                {
>                                        rid =
> c.getInt(c.getColumnIndex("RoomID"));
>                                        sid =
> c.getInt(c.getColumnIndex("SwitchID"));
>
>                                        roomName =
> c.getString(c.getColumnIndex("RoomName"));
>                                        switchName =
> c.getString(c.getColumnIndex("SwitchName"));
>
>                                        System.out.println
> (rid+":"+roomName+":"+sid
> +":"+switchName);
>
>                                }
>                                while (c.moveToNext());
>                                c.close();
>                        }
>                }
>
>        }
>        catch (SQLiteException se )
>        {
>                Log.e(getClass().getSimpleName(), "Could not create or Open
> the database");
>        }
>        finally
>        {
>                        sampleDB.close();
>        }
>    }
> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to