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
[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 - searching in sqllite then view from listview

searching in sqllite then view from listview

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

searching in sqllite then view from listview

Postby elbren » Sat Jul 13, 2013 4:29 am

I have the following code on how to retrieve data in sql lite database:
Syntax: [ Download ] [ Hide ]
Using php Syntax Highlighting
  1. public class DbManager {
  2.  
  3.                 Context context;
  4.                 private SQLiteDatabase db;
  5.                 private final String DBNAME = "studentsdb";
  6.                 private final int DBVER = 1;
  7.                 private final String TBLNAME = "students";
  8.                 final static String SID = "id";
  9.                 final static String SNAME = "name";
  10.                 final static String SCOURSE = "course";
  11.                
  12.                 public DbManager(Context context)
  13.                 {
  14.                         this.context = context;
  15.                         CustomHelper helper = new CustomHelper(context);
  16.                         this.db = helper.getWritableDatabase();
  17.                 }
  18.                 public ArrayList<ArrayList<Object>> getAllRowsAsArrays()
  19.                
  20.                 {
  21.                         ArrayList<ArrayList<Object>> dataArrays = new ArrayList<ArrayList<Object>>();
  22.                         Cursor cursor;
  23.                         try
  24.                         {
  25.                                 cursor = db.query(
  26.                                 TBLNAME,
  27.                                 new String[]{SID, SNAME, SCOURSE},
  28.                                 null, null, null, null, null
  29.                                 );
  30.                                 cursor.moveToFirst();
  31.                         if (!cursor.isAfterLast())
  32.                         {
  33.                         do
  34.                                 {
  35.                                         ArrayList<Object> dataList = new ArrayList<Object>();
  36.                                         dataList.add(cursor.getLong(0));
  37.                                         dataList.add(cursor.getString(1));
  38.                        
  39.                                         dataList.add(cursor.getString(2));
  40.                                         dataArrays.add(dataList);
  41.                                 }
  42.                         while (cursor.moveToNext());
  43.                         }
  44.                         }
  45.                         catch (SQLException e)
  46.                         {
  47.                         Log.e("DB Error", e.toString());
  48.                         e.printStackTrace();
  49.                         }
  50.                         return dataArrays;
  51.                 }
  52.                
  53.                 private class CustomHelper extends SQLiteOpenHelper
  54.                 {
  55.                 public CustomHelper(Context context)
  56.                 {
  57.                 super(context, DBNAME, null, DBVER);
  58.                 }
  59.                 @Override
  60.                 public void onCreate(SQLiteDatabase db)
  61.                 {
  62.                 String sql = "create table " + TBLNAME +
  63.                 " (" + SID + " integer primary key autoincrement not null,"
  64.                 + SNAME + " text," + SCOURSE + " text" + ");";
  65.                 db.execSQL(sql);
  66.                 }
  67.                 @Override
  68.                 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
  69.                 {
  70.                 db.execSQL("DROP TABLE IF EXISTS " + TBLNAME);
  71.                 onCreate(db);
  72.                 }
  73.                 }
  74. }
  75.  
Parsed in 0.025 seconds, using GeSHi 1.0.8.4


and this is how it retrieve it from my java class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Namelist extends Activity {
  2.         ListView listView;
  3.         DbManager db;
  4.         ImageView btnImageSearch;
  5.         String SName;
  6.         EditText name;
  7.         protected void onCreate(Bundle savedInstanceState) {
  8.                 super.onCreate(savedInstanceState);
  9.                 setContentView(R.layout.namelist);
  10.                
  11.                 db = new DbManager(this);
  12.                 listView = (ListView)findViewById(R.id.listView1);
  13.                 btnImageSearch = (ImageView)findViewById(R.id.imgSearch);
  14.                 name = (EditText)findViewById(R.id.editText1);
  15.                 displaySearch();
  16.                
  17.                 btnImageSearch.setOnClickListener(new OnClickListener() {
  18.                        
  19.                         @Override
  20.                         public void onClick(View v) {
  21.                                 SName = name.getText().toString();
  22.                                 if
  23.                                 (name.getText().toString().trim().equals(""))
  24.                                         displaySearch();
  25.                         else { 
  26.                                 displaySearch2();
  27.                         }
  28.                         }
  29.                 });
  30.         }
  31.          
  32.         private void displaySearch2() {
  33.                 // TODO Auto-generated method stub
  34.                    Toast.makeText(getApplicationContext(),SName , Toast.LENGTH_SHORT).show();
  35.                    ArrayList<ArrayList<Object>> data =db.getAllRowsAsArrays2(SName);
  36.                 final ArrayList<String> items = new ArrayList<String>();
  37.                 final ArrayAdapter<String> aa;
  38.                 aa = new ArrayAdapter<String>(this,
  39.                 android.R.layout.simple_list_item_1, items);
  40.                 for (int position = 0; position < data.size(); position++) {
  41.                 ArrayList<Object> row = (ArrayList<Object>) data.get(position);
  42.                 items.add("Id : " + row.get(0).toString() + "\nFirst Name : "+ row.get(1).toString() + "\nLast Name : "+ row.get(2).toString());
  43.                 aa.notifyDataSetChanged();     
  44.                 }
  45.                 listView.setAdapter(aa);
  46.                 }      
  47.        
  48.        
  49.            private void displaySearch() {
  50.                 // TODO Auto-generated method stub
  51.                 ArrayList<ArrayList<Object>> data = db.getAllRowsAsArrays();
  52.                 final ArrayList<String> items = new ArrayList<String>();
  53.                 final ArrayAdapter<String> aa;
  54.                 aa = new ArrayAdapter<String>(this,
  55.                 android.R.layout.simple_list_item_1, items);
  56.                 for (int position = 0; position < data.size(); position++) {
  57.                 ArrayList<Object> row = data.get(position);
  58.                 items.add("Id : " + row.get(0).toString() + "\nFirst Name : "
  59.                 + row.get(1).toString() + "\nLast Name : "
  60.                 + row.get(2).toString());
  61.                 aa.notifyDataSetChanged();     
  62.                 }
  63.                 listView.setAdapter(aa);
  64.                 }      
  65.        
  66.  
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


my problem is i want to search from database from lastname of firstname viewed in listview. i am using the displaySearch2 method, but i don't know how to do the methods from my dbmanager.

can this forum tell me the right track?
elbren
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Jul 13, 2013 4:17 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests