I've one listView with multiple choice and checkbox.
I get the values from listview executing a query in sqlite3.
When i click a button, I need to insert the selected items in another table but i don't know how can i do it.
Before doing insert i'm trying to know if it works showing one console log (Log.v). in this code there is not insert statement.
Any suggestions? Thanks in advance and sorry about my english,
Alex.
I paste the code:
public class productos extends Activity {
SQLiteDatabase db;
Spinner prodSpinner;
ArrayAdapter<String> prodAdapter;
Spinner catSpinner;
ArrayAdapter<String> catAdapter;
Cursor catCursor;
Cursor prodCursor;
String Value2;
String valor2;
SparseBooleanArray sp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.productos);
Bundle extras = getIntent().getExtras();
//final String Value = extras.getSerializable("Lista").toString();
//final String Value2 = extras.getSerializable("Super").toString();
Button CatText2 = (Button) findViewById(R.id.textCategoria);
CatText2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Log.v("valor4:", "AAAAA");
recCatSpinner();
}
});
Button btSelecciona = (Button) findViewById(R.id.btSelecciona);
btSelecciona.setOnClickListener(new OnClickListener() {
public void onClick (View arg0) {
Toast.makeText(getBaseContext(),"AAAA",Toast.LENGTH_SHORT).show();
}
});
Button btComanda = (Button) findViewById(R.id.btComanda);
btComanda.setOnClickListener(new OnClickListener() {
public void onClick (View arg0) {
EscriuComanda();
}
private void EscriuComanda() {
final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);
int count = 0;
//
sp = new SparseBooleanArray();
//SparseBooleanArray sp=prodSpinner.getCheckedItemPositions();
sp.clear();
sp = prodSpinner.getCheckedItemPositions();
for(int i = 0; i < sp.size(); i++)
{
if ( sp.valueAt(i)==true)
{
Log.v("400", "SI: " + valor2);
}
else
{
Log.v("500", "No: " + valor2);
}
}
}
});
//Toast.makeText(getBaseContext(),Value2,Toast.LENGTH_SHORT).show();
recCatSpinner();
}
public class UsuariosSQLiteHelper extends SQLiteOpenHelper {
public UsuariosSQLiteHelper(Context contexto, String nombre,
CursorFactory factory, int version) {
super(contexto, nombre, factory, version);
}
public void onCreate(SQLiteDatabase db) {
Log.v("OnClickV", "1");
}
public void onUpgrade(SQLiteDatabase db, int versionAnterior, int versionNueva) {
Log.v("OnClickV", "1");
}
}
public Cursor recuperaCategoria()
{
final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1);
final SQLiteDatabase db = usdbh.getWritableDatabase();
String tableName = "Categorias";
String[] columns = {"_id","Nombre"};
return db.query(tableName, columns, null, null, null, null, null);
}
public Cursor recuperaProductos()
{
final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1);
final SQLiteDatabase db = usdbh.getWritableDatabase();
String tableName = "ArtSuperV";
String[] columns = {"_id","NombreA"};
String where = "NombreC='" + valor2 + "'";
return db.query(tableName, columns, where, null, null, null, null);
}
public void recCatSpinner() {
final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);
catCursor = recuperaCategoria();
catCursor.moveToPosition(1);
catAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); //.simple_list_item_multiple_choice);// .simple_spinner_item);
catAdapter.setDropDownViewResource (android.R.layout.simple_list_item_multiple_choice); //.simple_spinner_dropdown_item);
prodSpinner.setAdapter(catAdapter);
if (catCursor.moveToFirst()) {
do {
catAdapter.add(catCursor.getString(1));
}
while (catCursor.moveToNext());
if (db != null) {
Toast.makeText(getBaseContext(),catCursor.getString(1),Toast.LENGTH_SHORT).show();
db.close();
}
}
startManagingCursor(catCursor);
catCursor.close();
prodSpinner.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view2, int pos, long id) {
valor2 = parent.getItemAtPosition(pos).toString();
Toast.makeText(getBaseContext(),valor2,Toast.LENGTH_SHORT).show();
Log.v("valor2:", valor2);
recProdSpinner();
}
});
}
public void recProdSpinner() {
final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);
prodCursor = recuperaProductos();
prodCursor.moveToPosition(1);
prodAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice); //.simple_list_item_multiple_choice);// .simple_spinner_item);
prodSpinner.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
prodAdapter.setDropDownViewResource (android.R.layout.simple_list_item_multiple_choice); //.simple_spinner_dropdown_item);
prodSpinner.setAdapter(prodAdapter);
if (prodCursor.moveToFirst()) {
do {
prodAdapter.add(prodCursor.getString(1));
}
while (prodCursor.moveToNext());
if (db != null) {
Toast.makeText(getBaseContext(),prodCursor.getString(1),Toast.LENGTH_SHORT).show();
db.close();
}
}
startManagingCursor(prodCursor);
prodCursor.close();
prodSpinner.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view2, int pos, long id) {
valor2 = parent.getItemAtPosition(pos).toString();
Toast.makeText(getBaseContext(),valor2,Toast.LENGTH_SHORT).show();
Log.v("valor2:", valor2);
}
});
}
}
Cant figure out some of the code flow due to language issue.But scheme should be:1. Set the adapters for both the lists (even if the lists are empty on launch, set the adapter with the empty but initialised array lists and make the array list as the global variables of the class so that they can be accessed from anywhere in the activity.) 2. Now select the items from the list1 and get their index in the first list.3. Add those items in the second array list. 4. Call the "notifyDataSetChanged()" for the adapter of the second list view.Link to know about proper use of "notifyDataSetChanged()" are notifyDataSetChanged example
Related
I have a class that extends ListFragment and uses a SimpleCursorAdapter. I have created 2 buttons that enables the user to select/deselect all in the list and this works fine. There could be 200 items in the list, so if they wanted to only select 190 of them, they could select all 200 then deselect 10.
The ListView uses setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
The problem is that I want the user to be able to individually deselect a row by long pressing the row. I use a setOnItemLongClickListener on the ListView but the view.isSelected is always returning false even when the row is selected.
Does anyone know why this is happening.
I've put log statements in to prove this fact.
I have also had a look around the net and some posts are saying that a possible problem is that I am using SimpleCursorAdapter and that it is too basic a component.
I'm not particularly good with adapters, lists and touch events, so could anyone point me in the right direction?
I suppose the obvious thing to tackle, is why the isSelected method always returns false.
public class CarerListForGroupMessageFragment extends ListFragment {
private static final String TAG = CarerListForGroupMessageFragment.class.getSimpleName();
RROnCallApplication rrOnCallApp;
Cursor cursor;
ListView listView;
MyAdapter myAdapter;
OnCarerForGroupMessageSelectedListener mListener;
EditText etext;
Button resetSearch;
Button selectAll;
Button deselectAll;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rrOnCallApp = (RROnCallApplication) getActivity().getApplicationContext();
cursor = getCarerList(null);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragmentcarerlistforgroupmessage, container, false);
}
#SuppressWarnings("deprecation")
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] from = new String[]{DBModel.C_CARER_FIRSTNAME, DBModel.C_CARER_LASTNAME, DBModel.C_CARER_PHONENUMBER};
int[] to = {R.id.carerrowfirstname, R.id.carerrowlastname, R.id.carerrowtelno};
myAdapter = (MyAdapter) new MyAdapter(getActivity(),R.layout.carerrow , cursor, from, to);
setListAdapter(myAdapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
getListView().setFastScrollEnabled(true);
getListView().setTextFilterEnabled(true);
selectAll = (Button) getActivity().findViewById(R.id.carerlistselectallgroupmessage);
selectAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
for(int i = 0; i < cursor.getCount(); i++){
getListView().setItemChecked(i, true);
}
myAdapter.notifyDataSetChanged();
}
});
deselectAll = (Button) getActivity().findViewById(R.id.carerlistdeselectallgroupmessage);
deselectAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
for(int i = 0; i < cursor.getCount(); i++) {
getListView().setItemChecked(i, false);
}
myAdapter.notifyDataSetChanged();
}
});
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(getActivity(), "On long click listener", Toast.LENGTH_LONG).show();
boolean ret = false;
if(! view.isSelected()) {
//row in list is not currently selected, so set it as selected
Log.e(TAG, "row postion " + position + " in list is not currently selected");
view.setSelected(true);
Cursor cursor = (Cursor) getListAdapter().getItem(position);
String carerID = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_ID));
String carerFirstName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_FIRSTNAME));
String carerLastName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_LASTNAME));
String carerTelNo = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_PHONENUMBER));
Log.e(TAG, "carerID = " + carerID);
mListener.onCarerForGroupMessageSelected(carerID, carerFirstName, carerLastName, carerTelNo, true);
getListView().setItemChecked(position, true);
myAdapter.notifyDataSetChanged();
ret = true;
} else {
Log.e(TAG, "row " + position + " in list is currently selected");
view.setSelected(false);
Cursor cursor = (Cursor) getListAdapter().getItem(position);
String carerID = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_ID));
String carerFirstName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_FIRSTNAME));
String carerLastName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_LASTNAME));
String carerTelNo = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_PHONENUMBER));
Log.e(TAG, "carerID = " + carerID);
mListener.onCarerForGroupMessageSelected(carerID, carerFirstName, carerLastName, carerTelNo, true);
getListView().setItemChecked(position, false);
myAdapter.notifyDataSetChanged();
ret = true;
}
return ret;
}
});
} // End of onActivityCreated
// Container Activity must implement this interface
public interface OnCarerForGroupMessageSelectedListener {
public void onCarerForGroupMessageSelected(String carerId, String carerFirstName, String carerLastName, String carerTelNo ,boolean longClick);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnCarerForGroupMessageSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnCarerForGroupMessageSelectedListener");
}
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
Log.e(TAG, "in onListItemClick");
v.setSelected(true);
//v.setBackgroundColor(Color.parseColor("#FF0000"));
TextView carerName = (TextView) getView().findViewById(R.id.textviewcarername);
Cursor cursor = (Cursor) getListAdapter().getItem(position);
String carerID = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_ID));
String carerFirstName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_FIRSTNAME));
String carerLastName = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_LASTNAME));
String carerTelNo = cursor.getString(cursor.getColumnIndex(DBModel.C_CARER_PHONENUMBER));
Log.e(TAG, "carerID = " + carerID);
mListener.onCarerForGroupMessageSelected(carerID, carerFirstName, carerLastName, carerTelNo, false);
getListView().setItemChecked(position, true);
myAdapter.notifyDataSetChanged();
}
private class MyAdapter extends SimpleCursorAdapter {
#SuppressWarnings("deprecation")
public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
}
#Override
public
View getView(int position, View convertView, ViewGroup parent) {
Log.e(TAG, "inside myadapter getview");
View v = super.getView(position, convertView, parent);
if(v == null)
return null;
Log.e(TAG, "clicked the listview!");
//Cursor c = (Cursor)getItem(position);
// String tagScanTime = c.getString(c.getColumnIndex(LoginValidate.C_TAG_SCAN_TIME));
// ((TextView)v.findViewById(R.id.rowcarername)).setText(name + " signed " + status +" at ");
return v;
}
}} //end of CarerListFragment
[EDIT 1]
DBModel class
public class DBModel {
private static final String TAG = DBModel.class.getSimpleName();
// table carer column names
public static final String C_CARER_ID_INDEX = BaseColumns._ID;
public static final String C_CARER_ID = "carerid";
public static final String C_CARER_FIRSTNAME = "carerfirstname";
public static final String C_CARER_LASTNAME = "carerlastname";
public static final String C_CARER_PHONENUMBER = "carerphonenumber";
public static final String C_CARER_EMAIL = "careremail";
Context context;
DBHelper dbhelper;
RROnCallApplication rrOnCallApplication;
public DBModel(Context context) {
this.context = context;
dbhelper = new DBHelper();
rrOnCallApplication = (RROnCallApplication) context.getApplicationContext();
}
/**
* inner class to create/open/upgrade database
*
* #author matt
*
*/
private class DBHelper extends SQLiteOpenHelper {
// database name and version number
public static final String DB_NAME = "roadrunneroncall.db";
public static final int DB_VERSION = 3;
// table names
public static final String TABLECARER = "carer";
public DBHelper() {
super(context, DB_NAME, null, DB_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
Log.e(TAG, "SQLiteOpenHelper oncreate ");
String sqlToCreateCarerTable = String
.format("create table %s ( %s INTEGER primary key, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)",
TABLECARER, C_CARER_ID_INDEX, C_CARER_ID, C_CARER_FIRSTNAME,
C_CARER_LASTNAME, C_CARER_PHONENUMBER, C_CARER_EMAIL);
db.execSQL(sqlToCreateCarerTable);
Log.e(TAG, "oncreate " + sqlToCreateCarerTable);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}//end of onUpgrade
}//end of DBHelper
public SQLiteDatabase getDB(){
return dbhelper.getWritableDatabase(RROnCallApplication.getSecretKey().toString());
}
public void deleteTableCarer() {
// open database
SQLiteDatabase db = dbhelper.getWritableDatabase(RROnCallApplication.getSecretKey().toString());
// delete contents of table
db.delete(DBHelper.TABLECARER, null, null);
// close database
// db.close();
}
public void insertIntoCarer(ContentValues cv) {
SQLiteDatabase db = dbhelper.getWritableDatabase(RROnCallApplication.getSecretKey().toString());
db.insertWithOnConflict(DBHelper.TABLECARER, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
// db.close();
}
public Cursor queryAllFromCarer() {
// open database
SQLiteDatabase db = dbhelper.getReadableDatabase(RROnCallApplication.getSecretKey().toString());
return db.query(DBHelper.TABLECARER, null, null, null, null, null, null);
}
Please check this code.
if(!getListView().isItemChecked(position))
instead of
if(! view.isSelected())
And keep boolean flag value inside DBModel class.
first time posting here, long time lurker. I am developing an Android app using an SQLite Database to persist data. The first view I have is a ListView where the user can add, change or delete Animal names. They can also hit an Edit Button, which brings them to a second view. This view has more details about the same animal, such as DOB and Comments, with the name and id transferred over from the first view.
The problem I am running into is I cannot figure out how to get the current animal's DOB and Comments to display in their respective EditTexts from the database. I have a save button at the bottom of this view that should save whatever info they put into these fields already, but then going back into this view needs to display whatever they have entered. My code for the two views and my DBHelper class is below. Thanks!
Here are images of what the two views look like.
ListView Primary View
Detail View
The MainActivity that contains the first view and the ListView:
public class MainActivity extends AppCompatActivity
{
public final static String ID_EXTRA = "com.example.josh.boergoats._ID";
public final static String NAME_EXTRA = "com.example.josh.boergoats.name";
private DBHelper dbHelper = null;
private Cursor cursor = null;
private DBAdapter adapter = null;
EditText editAnimal = null;
String animalId = null;
long idAnimal = 0;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listView);
editAnimal = (EditText) findViewById(R.id.animalEditText);
dbHelper = new DBHelper(this);
cursor = dbHelper.getAll();
startManagingCursor(cursor);
adapter = new DBAdapter(cursor);
listView.setAdapter(adapter);
Button addButton = (Button) findViewById(R.id.addButton);
addButton.setOnClickListener(onSave);
Button deleteButton = (Button) findViewById(R.id.deleteButton);
deleteButton.setOnClickListener(onDelete);
Button editButton = (Button) findViewById(R.id.editButton);
editButton.setOnClickListener(onEdit);
listView.setOnItemClickListener(onListClick);
}
catch (Exception e)
{
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
e.printStackTrace();
}
}
#Override
protected void onDestroy()
{
super.onDestroy();
dbHelper.close();
}
private View.OnClickListener onSave = new View.OnClickListener()
{
public void onClick(View v)
{
Button addButton = (Button) findViewById(R.id.addButton);
if (animalId == null)
{
dbHelper.insert(editAnimal.getText().toString());
}
else
{
dbHelper.update(animalId, editAnimal.getText().toString());
animalId = null;
}
cursor.requery();
editAnimal.setText("");
addButton.setText("Add Animal");
}
};
private View.OnClickListener onDelete = new View.OnClickListener()
{
public void onClick(View v)
{
if (animalId == null)
{
return;
}
else
{
dbHelper.delete(animalId);
animalId = null;
}
cursor.requery();
editAnimal.setText("");
Button addButton = (Button) findViewById(R.id.addButton);
addButton.setText("Add Animal");
}
};
private View.OnClickListener onEdit = new View.OnClickListener()
{
public void onClick(View v)
{
Button editButton = (Button) findViewById(R.id.editButton);
editButton.setVisibility(View.INVISIBLE);
Button addButton = (Button) findViewById(R.id.addButton);
addButton.setText("Add Animal");
Intent i = new Intent(MainActivity.this, DetailActivity.class);
//i.putExtra(ID_EXTRA, String.valueOf(id));
i.putExtra(NAME_EXTRA, String.valueOf(editAnimal.getText().toString()));
i.putExtra(ID_EXTRA, String.valueOf(idAnimal));
editAnimal.setText("");
startActivity(i);
}
};
private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
animalId = String.valueOf(id);
Cursor c = dbHelper.getById(animalId);
c.moveToFirst();
editAnimal.setText(dbHelper.getAnimal(c));
Button addButton = (Button) findViewById(R.id.addButton);
addButton.setText("Update");
Button editButton = (Button) findViewById(R.id.editButton);
editButton.setVisibility(View.VISIBLE);
idAnimal = id;
}
};
public class DBAdapter extends CursorAdapter
{
DBAdapter(Cursor c)
{
super(MainActivity.this, c);
}
#Override
public void bindView(View view, Context context, Cursor c)
{
DBHolder holder = (DBHolder) view.getTag();
holder.populateFrom(c, dbHelper);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.row, parent, false);
DBHolder holder = new DBHolder(row);
row.setTag(holder);
return(row);
}
}
static class DBHolder
{
private TextView name = null;
DBHolder(View row)
{
name = (TextView) row.findViewById(R.id.nameTextView);
}
void populateFrom(Cursor c, DBHelper helper)
{
//name.setText(r.getName(c));
name.setText(helper.getAnimal(c));
}
}
}
The second activity, DetailActivity, where I am having the problem.
public class DetailActivity extends AppCompatActivity
{
private DBHelper dbHelper = null;
//private Cursor cursor = null;
String passedName = null;
String passedID = null;
private EditText passedIdView = null;
private EditText passedNameView = null;
private EditText dobView = null;
private EditText commentsView = null;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
//dbHelper = new DBHelper(this);
//cursor = dbHelper.getAllInfo();
passedName = getIntent().getStringExtra(MainActivity.NAME_EXTRA);
passedNameView = (EditText) findViewById(R.id.nameDetailEditText);
passedNameView.setText(passedName);
passedID = getIntent().getStringExtra(MainActivity.ID_EXTRA);
passedIdView = (EditText) findViewById(R.id.idDetailEditText);
passedIdView.setText(passedID);
dobView = (EditText) findViewById(R.id.dobDetailEditText);
commentsView = (EditText) findViewById(R.id.commentsDetailEditText);
Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(onSave);
}
private View.OnClickListener onSave = new View.OnClickListener()
{
public void onClick(View v)
{
String id = passedID;
passedID = getIntent().getStringExtra(MainActivity.ID_EXTRA);
if (passedNameView.getText().toString() != null)
{
if (passedID != null)
{
dbHelper.update(id, passedNameView.getText().toString());
}
}
if (dobView.getText().toString() != null)
{
dbHelper.updateDob(id, dobView.getText().toString());
}
if (commentsView.getText().toString() != null)
{
dbHelper.updateComments(id, commentsView.getText().toString());
}
//reset all edittext fields to blank before leaving
passedIdView.setText("");
passedNameView.setText("");
dobView.setText("");
commentsView.setText("");
Intent i = new Intent(DetailActivity.this, MainActivity.class);
startActivity(i);
}
};
}
The Database Helper class, where the database is created and manipulated. Note that not all of the methods are being used, a few of them are from my experimenting.
public class DBHelper extends SQLiteOpenHelper
{
private static final String dbPath = "/data/data/com.example.josh.boergoats/";
private static final String dbName = "animals.db";
private static final int schemaVersion = 1;
public DBHelper(Context context)
{
super(context, dbName, null, schemaVersion);
//this.myContext = context;
}
#Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE Animals (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, dob TEXT, comments TEXT);");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
}
public void insert(String animal)
{
ContentValues cv = new ContentValues();
cv.put("name", animal);
getWritableDatabase().insert("Animals", "name", cv);
}
public void update(String id, String animal)
{
ContentValues cv = new ContentValues();
String[] args = {id};
cv.put("name", animal);
getWritableDatabase().update("Animals", cv, "_id=?", args);
}
public void updateDob(String id, String dob)
{
ContentValues cv = new ContentValues();
String[] args = {id};
cv.put("dob", dob);
getWritableDatabase().update("Animals", cv, "_id=?", args);
}
public void updateComments(String id, String comment)
{
ContentValues cv = new ContentValues();
String[] args = {id};
cv.put("comments", comment);
getWritableDatabase().update("Animals", cv, "_id=?", args);
}
public void delete(String id)
{
getWritableDatabase().delete("Animals", "_id=?", new String[] {id});
}
public Cursor getAll()
{
return(getReadableDatabase().rawQuery("SELECT _id, name FROM Animals", null));
}
public Cursor getAllInfo()
{
return(getReadableDatabase().rawQuery("SELECT _id, name, dob, comments FROM Animals", null));
}
public String getAnimal(Cursor c)
{
return(c.getString(1));
}
public String getDob(Cursor c)
{
return(c.getString(2));
}
public String getComments(Cursor c)
{
return(c.getString(3));
}
public Cursor getById(String id)
{
String[] args = {id};
return(getReadableDatabase().rawQuery("SELECT _id, name FROM Animals WHERE _id=?", args));
}
}
Thank you again in advance.
What I do, to use the same activity to add or edit (which I believe is what you're trying to do), is to pass, via an Intent Extra, the respective option and then have the code set the respective values. here's an example :-
String caller = getIntent().getStringExtra("Caller");
if(getIntent().getStringExtra("Caller").equals("ShopListByCursorActivityUpdate")) {
((EditText) findViewById(R.id.ase_storename_input)).setText(getIntent().getStringExtra("ShopName"));
((EditText) findViewById(R.id.ase_storeorder_input)).setText(getIntent().getStringExtra("ShopOrder"));
((EditText) findViewById(R.id.ase_storestreet_input)).setText(getIntent().getStringExtra("ShopStreet"));
((EditText) findViewById(R.id.ase_storecity_input)).setText(getIntent().getStringExtra("ShopCity"));
((EditText) findViewById(R.id.ase_storestate_input)).setText(getIntent().getStringExtra("ShopState"));
((EditText) findViewById(R.id.ase_storephone_input)).setText(getIntent().getStringExtra("ShopPhone"));
((EditText) findViewById(R.id.ase_storenotes_input)).setText(getIntent().getStringExtra("ShopNotes"));
setTitle(getResources().getString(R.string.title_activity_shop_edit));
}
The 2nd Line checks for the Update mode (ie what is in the Intent Extra named Caller (extracted into caller)) and then sets the respective values which themselves are in Intent Extras. 1st line isn't needed I just had it there for debugging purposes.
Note the when called by Edit as opposed to Add then the Intent Extra Caller is set to ShopListByCursorActivityUpdate when adding is is set to ShopListByCursorActivity.
PS You may have issues in the first activity not displaying the changed/saved data as it doesn't appear that you refresh the data. In brief, if this is an issue. You need to rebuild the cursor (ie redo the query) and then get the adapter to use the new/amended cursor via changeCursor, SwapCursor or notifyDataSetChanged. eg :-
Cursor csr = shopperdb.getShopsAsCursor();
currentsca.swapCursor(csr);
In regards to comment
You are on the right track, but I was actually having trouble putting the information that I needed into the Intent Extra. Since I don't have the DOB or comments field on my first activity, I need to pull that information from my database and put it into the Intent Extra somehow. Those 2 fields are created in my DBHelper class. Also, depending on how they can be pulled from the database, they may not even need to be put in the Intent Extra if they can be put straight into my EditTexts.
Then Use SELECT * FROM Animals to get all columns in getAll then all columns will be available in the returned Cursor.
All i tried is to pass the listview selected items id to the next activity and show the id in a TextView on another page. I receive a number format exception when i click on list item. Any suggestions please.
DataBaseWrapper is the class where database is created.
DishOperation
public class DishOperation {
// Database fields
private DataBaseWrapper dbHelper;
private String[] DISHES_TABLE_COLUMNS = { DataBaseWrapper.DISHES_ID, DataBaseWrapper.DISHES_NAME,DataBaseWrapper.DISHES_INGREDIENTS };
private SQLiteDatabase database;
public DishOperation(Context context) {
dbHelper = new DataBaseWrapper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close()
{
dbHelper.close();
}
public Dish addDishes(String name,String ingredients) {
ContentValues values = new ContentValues();
values.put(DataBaseWrapper.DISHES_NAME, name);
values.put(DataBaseWrapper.DISHES_INGREDIENTS, ingredients);
long dishId = database.insert(DataBaseWrapper.DISHES, null, values);
// now that the student is created return it ...
Cursor cursor = database.query(DataBaseWrapper.DISHES,
DISHES_TABLE_COLUMNS, DataBaseWrapper.DISHES_ID + " = "
+ dishId, null, null, null, null);
cursor.moveToFirst();
Dish newComment = parseDishes(cursor);
cursor.close();
return newComment;
}
public void deleteDishes(Dish comment) {
long id = comment.getId();
System.out.println("Comment deleted with id: " + id);
database.delete(DataBaseWrapper.DISHES, DataBaseWrapper.DISHES_ID + " = " + id, null);
}
public List getAllDishes() {
List dishes = new ArrayList();
Cursor cursor = database.query(DataBaseWrapper.DISHES,
DISHES_TABLE_COLUMNS, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Dish dish = parseDishes(cursor);
dishes.add(dish);
cursor.moveToNext();
}
cursor.close();
return dishes;
}
public String getInformation(Dish i)
{
long id=i.getId();
String ing= i.getIngredients();
return ing;
}
private Dish parseDishes(Cursor cursor) {
Dish dish = new Dish();
dish .setId((cursor.getInt(0)));
dish .setName(cursor.getString(1));
dish .setIngredients(cursor.getString(2));
return dish ;
}
}
Activity 1
public void onCreate(Bundle savedInstanceState) {
Button btListe;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dishDBoperation = new DishOperation(this);
dishDBoperation.open();
final List values = dishDBoperation.getAllDishes();
final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, Result.class);
intent.putExtra("key",id);
startActivity(intent);
}
});
Activity 2
int value;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView text = (TextView) findViewById(R.id.editText3);
Bundle extras = getIntent().getExtras();
if (extras != null) {
long value = extras.getLong("key");
text.setText(String.valueOf(value));// updated!!
}
}
Change
value =Integer.parseInt( extras.getString("key"));
with
long value = extras.getLong("key");
also in your Activity2 you should move
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
in the very beginning of onCreate otherwise your findViewById will return null.
Edit.
Accordingly to the code you posted you have an ArrayAdapter of Dish. Your dataset and your ArrayAdapter should reflect it, and this can be done with Generics.
To get the id of your row as argument of onItemClick, you have to override getItemId. E.g.
setListAdapter(new ArrayAdapter<Dish>(this, android.R.layout.simple_list_item_1, values ) {
#Override
public long getItemId(int position) {
return getItem(position).getId();
}
}));
You should use value = extras.getLong("key"));
In Activity 1, id is of type long and in Activity 2, you try to retrieve it as a String.
Retrieve it by extras.getLong("key");
I'm trying to show contact data in a listview. I think all it's ok but when I execute the app I have the follow error java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView.
The code is this:
public class BuscaContactos extends Activity {
ListView listContactos;
String opcion;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_busca_contactos);
listContactos=(ListView)findViewById(R.id.listContactos);
ArrayList<String> listagente = consultaAgenda();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(BuscaContactos.this, R.layout.activity_busca_contactos,listagente);
listContactos.setAdapter(adapter);
listContactos.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
private ArrayList<String> consultaAgenda() {
ArrayList<String> datos = new ArrayList<String>();
Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (c.moveToNext()) {
String ContactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
String nombre = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
datos.add(ContactID);
datos.add(nombre);
}
c.close();
return datos;
}
}
R.layout.activity_busca_contactos should contain a TextView nothing else.
If you want to use other View then you need to create a CustomAdapter
I have a spinner that show my data list from a database SQLite.. I want to remove a row from Spinner and db when selected then clicked button btn. How can I do this? Thanks
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.remove_wf2);
mDB = new MyDatabase(getApplicationContext());
mDB.open();
spin = (Spinner)findViewById(R.id.wf_spinner);
c = mDB.fetchWfs();
startManagingCursor(c);
// create an array to specify which fields we want to display
String[] from = new String[]{WfMetaData.WF_NAME_KEY};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
// create simple cursor adapter
adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
// get reference to our spinner
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
spinnerPos = pos;
mRowId = id; // database row id
}
});
//fillSpinner(spin);
Button btn = (Button)findViewById(R.id.button11);
btn.setText("Rimuovi");
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDB.delete_byID(mRowId);
c.requery();
}
});
/*
Spinner spin = (Spinner)findViewById(R.id.wf_spinner);
Cursor cur = mDB.fetchWfs();
startManagingCursor(cur);
String[] from = new String[] { WfMetaData.WF_NAME_KEY };
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter spinAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cur, from, to);
spinAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(spinAdapter);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Cursor c = (Cursor)parent.getItemAtPosition(pos);
mSpinnerWF = c.getInt(c.getColumnIndexOrThrow(WfMetaData.WF_NAME_KEY));
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});*/
//mDB.close();
}
My delete method is this:
public boolean delete_byID(long rowId) {
return mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "=" + rowId, null) > 0;
CharSequence text = "Il Workflow "+ n +" è stato rimosso con successo!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(mContext, text, duration);
toast.show();
}
I don't find any delete method from ID. Is this a db method?
I've modified my app like this:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.remove_wf2);
mDB = new MyDatabase(getApplicationContext());
mDB.open();
spin = (Spinner)findViewById(R.id.wf_spinner);
c = mDB.fetchWfs();
startManagingCursor(c);
// create an array to specify which fields we want to display
String[] from = new String[]{WfMetaData.WF_NAME_KEY};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
// create simple cursor adapter
adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
// get reference to our spinner
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
spinnerPos = pos;
mRowId = id; // database row id
}
});
//fillSpinner(spin);
mDB.close();
Button btn = (Button)findViewById(R.id.button11);
btn.setText("Rimuovi");
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
adapter.getItem(spinnerPos);
mDB.delete_byName((String)adapter.getItem(spinnerPos));
c.requery();
}
});
but I get this error in LogCat(Cast exception):
05-10 15:46:38.586: D/RadioSignalLevel(1758): Gsm Radio Signal level: 4
05-10 15:46:38.586: D/StatusBarPolicy(1758): ERI alert sound is disabled.
05-10 15:46:38.606: D/NetworkService(1939): handle message:800
05-10 15:46:38.606: D/NetworkService(1939): getRawGPRSRegistrationState
05-10 15:46:38.616: I/TransactionService(29090): MMS-STATUS - start transaction service, app version=STABLE4.5.user.4.5.2A-74_OLE-31.2.3.4.Blur_Version.45.31.0.MB860.TIM.en.IT.Thu Sep 22 04:02:02 CST 2011 (log=false) (apn=false) (config=false)
05-10 15:46:38.626: I/SmsReceiverService(29090): MMS-STATUS - start sms receiver service, app version=STABLE4.5.user.4.5.2A-74_OLE-31.2.3.4.Blur_Version.45.31.0.MB860.TIM.en.IT.Thu Sep 22 04:02:02 CST 2011 (log=false) (apn=false) (config=false)
05-10 15:46:38.636: I/TelephonyRegistry(1610): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=nwTypeChanged interfaceName=null networkType=10
05-10 15:46:38.636: I/SYS_MPP(1965): WebtopStatusHandler updateDataIcon()
05-10 15:46:38.646: D/NetworkService(1939): handle message:800
05-10 15:46:38.646: D/NetworkService(1939): getRawGPRSRegistrationState
05-10 15:46:38.646: I/CBStartup(1939): onServiceStateChanged
05-10 15:46:38.656: I/CBSettings(1939): Reading database: KEY_NAME= db_key_language
05-10 15:46:38.656: I/CBSettings(1939): Reading database: KEY_NAME= db_key_channel
public class MyDatabase {
SQLiteDatabase mDb;
DbHelper mDbHelper;
Context mContext;
private static final String DEBUG_TAG = "WFListDatabase";
private static final String DB_NAME="WFListdb";//nome del db
private static final int DB_VERSION=1; //numero di versione del nostro db
public MyDatabase(Context ctx) {
mContext = ctx;
mDbHelper = new DbHelper(ctx, DB_NAME, null, DB_VERSION); //quando istanziamo questa classe, istanziamo anche l'helper (vedi sotto)
}
public void open(){ //il database su cui agiamo è leggibile/scrivibile
mDb=mDbHelper.getWritableDatabase();
}
public void close(){ //chiudiamo il database su cui agiamo
mDb.close();
}
public void insertWf(String name,String cls){ //metodo per inserire i dati
ContentValues cv=new ContentValues();
cv.put(WfMetaData.WF_NAME_KEY, name);
cv.put(WfMetaData.WF_CLASS_KEY, cls);
mDb.insert(WfMetaData.WF_TABLE, null, cv);
}
/*public void removeWf(String name,String cls){ //metodo per inserire i dati
ContentValues cv=new ContentValues();
cv.remove(WfMetaData.WF_NAME_KEY);
cv.remove(WfMetaData.WF_CLASS_KEY);
mDb.(WfMetaData.WF_TABLE, null, cv);
}*/
public Cursor fetchAllWfs(){ //metodo per fare la query di tutti i dati
return mDb.query(WfMetaData.WF_TABLE, new String[]{WfMetaData.WF_NAME_KEY, WfMetaData.WF_CLASS_KEY},null,null,null,null,null);
}
static class WfMetaData { // i metadati della tabella, accessibili ovunque
static final String WF_TABLE = "wfs";
static final String ID = "_id";
static final String WF_NAME_KEY = "name";
static final String WF_CLASS_KEY = "class";
}
private static final String WF_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " //codice sql di creazione della tabella
+ WfMetaData.WF_TABLE + " ("
+ WfMetaData.ID+ " integer primary key autoincrement, "
+ WfMetaData.WF_NAME_KEY + " text not null, "
+ WfMetaData.WF_CLASS_KEY + " text not null);";
public Cursor fetchWfs(){ //metodo per fare la query di tutti i dati
return mDb.query(WfMetaData.WF_TABLE, null,null,null,null,null,null);
}
public void delete_byName(String n){
mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "='" +n + "'", null);
//mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "=?", new String[] { n });
CharSequence text = "Il Workflow "+ n +" è stato rimosso con successo!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(mContext, text, duration);
toast.show();
}
public void delete_byID(long rowId) {
mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "=" + rowId, null);
CharSequence text = "Il Workflow è stato rimosso con successo!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(mContext, text, duration);
toast.show();
}
private class DbHelper extends SQLiteOpenHelper { //classe che ci aiuta nella creazione del db
public DbHelper(Context context, String name, CursorFactory factory,int version) {
super(context, name, factory, version);
}
#Override
public void onCreate(SQLiteDatabase _db) { //solo quando il db viene creato, creiamo la tabella
_db.execSQL(WF_TABLE_CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase _db, int oldVersion, int newVersion) {
Log.w(DEBUG_TAG, "Upgrading database. Existing contents will be lost. ["
+ oldVersion + "]->[" + newVersion + "]");
_db.execSQL("DROP TABLE IF EXISTS " + WF_TABLE_CREATE);
onCreate(_db);
}
}
public boolean isEmpty(){
boolean isEmpty = true;
Cursor cursor = mDb.query(WfMetaData.WF_TABLE, new String[] { WfMetaData.WF_NAME_KEY }, null, null, null, null, null);
if (cursor != null && cursor.getCount() > 0)
{
isEmpty = false;
}
return isEmpty;
}
}
public class RemoveWorkflow2 extends Activity {
private EditText nameEditText;
private EditText classEditText;
//private EditText idEditText;
//private int mSpinnerWF;
Spinner spin;
WorkflowChoice wf = new WorkflowChoice();
MyDatabase mDB;
SimpleCursorAdapter adapter;
private long mRowId;
private int spinnerPos;
private String delString;
Cursor c;
//MyDatabase mDB = wf.getDb();
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.remove_wf2);
mDB = new MyDatabase(getApplicationContext());
mDB.open();
spin = (Spinner)findViewById(R.id.wf_spinner);
c = mDB.fetchWfs();
startManagingCursor(c);
// create an array to specify which fields we want to display
String[] from = new String[]{WfMetaData.WF_NAME_KEY};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
// create simple cursor adapter
adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
// get reference to our spinner
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Cursor c = (Cursor)(parent.getAdapter().getItem(pos));
delString = c.getString(c.getColumnIndex(mDB.);
//spinnerPos = pos;
//mRowId = id; // database row id
}
});
//fillSpinner(spin);
Button btn = (Button)findViewById(R.id.button11);
btn.setText("Rimuovi");
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDB.delete_byID(mRowId);
mDB.delete_byName(delString);
c.requery();
}
});
}
private void fillSpinner(Spinner s){
Cursor c = mDB.fetchWfs();
startManagingCursor(c);
// create an array to specify which fields we want to display
String[] from = new String[]{WfMetaData.WF_NAME_KEY};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
// create simple cursor adapter
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
// get reference to our spinner
s.setAdapter(adapter);
}
}
I have a problem in method:
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Cursor c = (Cursor)(parent.getAdapter().getItem(pos));
delString = c.getString(c.getColumnIndex(mDB.);
//spinnerPos = pos;
//mRowId = id; // database row id
}
How can I set delString? I don't have YOUR_COLUMN_ID.. How can I resolve it? THANKS
I'm assuming the button is outside the spinner...
You don't really need the position. Set a class variable:
private int spinnerPos;
private long mRowId;
Add this for your spinner:
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
spinnerPos = pos;
mRowId = id; // database row id
}
});
Then for your button:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Your code to get the string from the adapter
mDB.delete_byName(yourString);
c.requery();
});
By the way, you should leave your DB open until you are exiting the app.
I see you asking a question about deleting by id. In your database class you would have something like this:
public boolean delete(long rowId) {
return mDb.delete(TABLE_NAME, TABLE_ROWID + "=" + rowId, null) > 0;
}
Hope this helps!
EDIT
Better method:
Private String delString;
Add this for your spinnerListener
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Cursor c = (Cursor) (parent.getAdapter().getItem(pos));
delString = c.getString(c.getColumnIndex(YourDB.YOUR_COLUMN_ID)); }
});
Button:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDB.delete_byName(delString);
c.requery();
});
EDIT 2
First Method for delete (by RowId):
public boolean delete_byID(long rowId) {
return mDb.delete(WfMetaData.WF_TABLE, WfMetaData.ID + "=" + rowId, null) > 0;
}
Second Method for delete (by name):
public boolean delete_byName(String name) {
return mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "= '" + name + "'", null) > 0;
}