Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Need help in code

Need help in code

General Android Books.
Also feel free to comment, improve and contribute to AndBook, the free Android Learners book.

Need help in code

Postby manish3548 » Wed Jun 09, 2010 8:17 am

Hi,

I have contact data in sqlite and i want to show data in android app, but i am able to show only one column(name). How can i show all columns(Phone No, Email etc).
Below is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class DataHelper {
  2.          
  3.            private static final String DATABASE_NAME = "Address.db";
  4.            private static final int DATABASE_VERSION = 1;
  5.            private static final String TABLE_NAME = "Contact";
  6.          
  7.            private Context context;
  8.            private SQLiteDatabase db;
  9.          
  10.            private SQLiteStatement insertStmt;
  11.            private static final String INSERT = "insert into "
  12.               + TABLE_NAME + "(name) values (?)";
  13.          
  14.            public DataHelper(Context context) {
  15.       this.context = context;
  16.               OpenHelper openHelper = new OpenHelper(this.context);
  17.               this.db = openHelper.getWritableDatabase();
  18.               this.insertStmt = this.db.compileStatement(INSERT);
  19.            }
  20.          
  21.            public long insert(String name) {
  22.               this.insertStmt.bindString(1, name);
  23.              
  24.               return this.insertStmt.executeInsert();
  25.            }
  26.          
  27.            public void deleteAll() {
  28.               this.db.delete(TABLE_NAME, null, null);
  29.            }
  30.          
  31.    public List<String> selectAll() {
  32.               List<String> list = new ArrayList<String>();
  33.               Cursor cursor = this.db.query(TABLE_NAME, new String[] { "name" },
  34.                 null, null, null, null, "name desc");
  35.               if (cursor.moveToFirst()) {
  36.                  do {
  37.                     list.add(cursor.getString(0));
  38.                    
  39.                  } while (cursor.moveToNext());
  40.               }
  41.               if (cursor != null && !cursor.isClosed()) {
  42.                  cursor.close();
  43.               }
  44.               return list;
  45.            }
  46.          
  47.            private static class OpenHelper extends SQLiteOpenHelper {
  48.          
  49.               OpenHelper(Context context) {
  50.                  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  51.               }
  52.          
  53.       @Override
  54.               public void onCreate(SQLiteDatabase db) {
  55.                  db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)");
  56.               }
  57.          
  58.               @Override
  59.       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  60.                  Log.w("Example", "Upgrading database, this will drop tables and recreate.");
  61.                  db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
  62.                  onCreate(db);
  63.               }
  64.            }
  65.         }
  66.  
  67.  
  68. public class DatabaseActivity extends Activity {
  69.        
  70.           private TextView output1;
  71. //        private TextView output2;
  72. //        private TextView output3;
  73.            
  74.            private DataHelper dh;
  75.            
  76.             @Override
  77.             public void onCreate(Bundle savedInstanceState) {
  78.                 super.onCreate(savedInstanceState);
  79.                 setContentView(R.layout.main);
  80.                  
  81.                 this.output1 = (TextView) this.findViewById(R.id.Name);
  82.           //      this.output2 = (TextView) this.findViewById(R.id.PhoneNo);
  83.          //      this.output3 = (TextView) this.findViewById(R.id.Email);
  84.                
  85.                
  86.                  
  87.                 this.dh = new DataHelper(this);
  88.                 this.dh.deleteAll();
  89.                 this.dh.insert("Manish");
  90.                        
  91.                 List<String> names = this.dh.selectAll();
  92.                 StringBuilder sb = new StringBuilder();
  93.                 sb.append("Names in database:\n");
  94.                 for (String name : names) {
  95.                    sb.append(name + "\n");
  96.                  
  97.                 }
  98.                  
  99.                 Log.d("ADDRESS", "names size - " + names.size());
  100.                  
  101.                 this.output1.setText(sb.toString());
  102.           //      this.output2.setText(sb.toString());
  103.           //      this.output3.setText(sb.toString());
  104.                  
  105.             }
  106.         }
Parsed in 0.017 seconds, using GeSHi 1.0.8.4
manish3548
Freshman
Freshman
 
Posts: 3
Joined: Wed Jun 09, 2010 8:08 am

Top

Re: Need help in code

Postby Openxcell » Sat Apr 02, 2011 3:23 am

manish3548 wrote:Hi,

I have contact data in sqlite and i want to show data in android app, but i am able to show only one column(name). How can i show all columns(Phone No, Email etc).
Below is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class DataHelper {
  2.          
  3.            private static final String DATABASE_NAME = "Address.db";
  4.            private static final int DATABASE_VERSION = 1;
  5.            private static final String TABLE_NAME = "Contact";
  6.          
  7.            private Context context;
  8.            private SQLiteDatabase db;
  9.          
  10.            private SQLiteStatement insertStmt;
  11.            private static final String INSERT = "insert into "
  12.               + TABLE_NAME + "(name) values (?)";
  13.          
  14.            public DataHelper(Context context) {
  15.       this.context = context;
  16.               OpenHelper openHelper = new OpenHelper(this.context);
  17.               this.db = openHelper.getWritableDatabase();
  18.               this.insertStmt = this.db.compileStatement(INSERT);
  19.            }
  20.          
  21.            public long insert(String name) {
  22.               this.insertStmt.bindString(1, name);
  23.              
  24.               return this.insertStmt.executeInsert();
  25.            }
  26.          
  27.            public void deleteAll() {
  28.               this.db.delete(TABLE_NAME, null, null);
  29.            }
  30.          
  31.    public List<String> selectAll() {
  32.               List<String> list = new ArrayList<String>();
  33.               Cursor cursor = this.db.query(TABLE_NAME, new String[] { "name" },
  34.                 null, null, null, null, "name desc");
  35.               if (cursor.moveToFirst()) {
  36.                  do {
  37.                     list.add(cursor.getString(0));
  38.                    
  39.                  } while (cursor.moveToNext());
  40.               }
  41.               if (cursor != null && !cursor.isClosed()) {
  42.                  cursor.close();
  43.               }
  44.               return list;
  45.            }
  46.          
  47.            private static class OpenHelper extends SQLiteOpenHelper {
  48.          
  49.               OpenHelper(Context context) {
  50.                  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  51.               }
  52.          
  53.       @Override
  54.               public void onCreate(SQLiteDatabase db) {
  55.                  db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)");
  56.               }
  57.          
  58.               @Override
  59.       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  60.                  Log.w("Example", "Upgrading database, this will drop tables and recreate.");
  61.                  db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
  62.                  onCreate(db);
  63.               }
  64.            }
  65.         }
  66.  
  67.  
  68. public class DatabaseActivity extends Activity {
  69.        
  70.           private TextView output1;
  71. //        private TextView output2;
  72. //        private TextView output3;
  73.            
  74.            private DataHelper dh;
  75.            
  76.             @Override
  77.             public void onCreate(Bundle savedInstanceState) {
  78.                 super.onCreate(savedInstanceState);
  79.                 setContentView(R.layout.main);
  80.                  
  81.                 this.output1 = (TextView) this.findViewById(R.id.Name);
  82.           //      this.output2 = (TextView) this.findViewById(R.id.PhoneNo);
  83.          //      this.output3 = (TextView) this.findViewById(R.id.Email);
  84.                
  85.                
  86.                  
  87.                 this.dh = new DataHelper(this);
  88.                 this.dh.deleteAll();
  89.                 this.dh.insert("Manish");
  90.                        
  91.                 List<String> names = this.dh.selectAll();
  92.                 StringBuilder sb = new StringBuilder();
  93.                 sb.append("Names in database:\n");
  94.                 for (String name : names) {
  95.                    sb.append(name + "\n");
  96.                  
  97.                 }
  98.                  
  99.                 Log.d("ADDRESS", "names size - " + names.size());
  100.                  
  101.                 this.output1.setText(sb.toString());
  102.           //      this.output2.setText(sb.toString());
  103.           //      this.output3.setText(sb.toString());
  104.                  
  105.             }
  106.         }
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


You can refer to the link given below, might help you.
Openxcell
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Mon Mar 28, 2011 1:59 pm

Top

Return to Android Books

Who is online

Users browsing this forum: No registered users and 1 guest