From any Java class cal DataBase by using the following code :
context = this;
dbutil = new DbUtil(context);
dbutil.open();
To set Database value into the Spinner through ArrayList:
Spinner spnCatname;ArrayList<String> array = dbutil.getcategoryname();
ArrayAdapter<String> spinnerArray = new ArrayAdapter<String>(context,R.layout.spinner_text, array);
spnCatname.setAdapter(spinnerArray);
How to call database value using Cursor? // Nested Cursor
Cursor cur = dbutil.getProductName(data); // Using Parameterif (cur != null && cur.moveToFirst()) {
cur.moveToFirst();
String Catid = cur.getString(cur.getColumnIndex(DbHelper.CATEGORY_CODE_FIELD));
dbutil.open();
Cursor spincur = dbutil.getCatgoryname(Catid);
if (spincur.moveToFirst() && spincur != null) {
spincur.moveToFirst();
String CatSpinId = spincur.getString(spincur.getColumnIndex(DbHelper.CATEGORY_NAME));
int id = array.indexOf(CatSpinId); // Getting item Id of spinner selected data
spnCatname.setSelection(id); //Set it into Spinner
}
}
How to insert & update values into DataBase?
dbutil.addproduct(pid, pname, categoryid, img); // Insert
dbutil.updateCode(DbHelper.PRODUCT_ID_FIELD,pid); // Update
Need to get Phone Number:
TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);String mPhoneNumber = tMgr.getLine1Number();
Comments
Post a Comment