pas SQL query result to listView android - android

I have a problem in my list view. when I pass My SQL query to ListView then list view show this in each row
*com.MyPackageName.MyAppName.MyClassName#Some Number (like 2c62a7d0) *
I dont know why
this is my Function that return everything
public List<AddedZekrView> getAllRecordList(){
ArrayList<AddedZekrView> addedZekrFields = new ArrayList<AddedZekrView>();
//Cursor cursor= database.query(ZekrdbOpenHelper.TABLE_ZEKR, allColumns, null, null, null, null, null);
Cursor cursor= database.query(ZekrdbOpenHelper.TABLE_ZEKR, allColumns, null, null, null, null, null);
if (cursor.getCount()>0) {
cursor.moveToFirst();
while (cursor.moveToNext()) {
Log.i("In while", cursor.getPosition()+"");
AddedZekrView addedZekrFieldNew=new AddedZekrView();
// you have to declare all fields such as **COLUMN_ID** in your addedZekrView activity
addedZekrFieldNew.ID=cursor.getLong(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_ID));
addedZekrFieldNew.TITLE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_TITLE));
addedZekrFieldNew.DESC=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_DESC));
addedZekrFieldNew.MAX_COUNT=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_MAX_COUNT));
addedZekrFieldNew.CREATE_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_CREATE_DATE));
addedZekrFieldNew.LAST_COUNT_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_LAST_COUNT_DATE));
addedZekrFieldNew.MODIFY_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_MODIFY_DATE));
addedZekrFieldNew.EXPIRATION_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_EXPIRATION_DATE));
addedZekrFieldNew.START_AZ=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_START_AZ));
Log.i("return cursor", addedZekrFieldNew.TITLE+ " " +addedZekrFieldNew.DESC);
addedZekrFields.add(addedZekrFieldNew);
}
}
//return List Object
return addedZekrFields;
}
and this is my java file:
public class AddedZekrView extends ListActivity {
public Long ID;
public String TITLE;
public String DESC;
public String MAX_COUNT;
public String CREATE_DATE;
public String CURENT_COUNT;
public String LAST_COUNT_DATE;
public String MODIFY_DATE;
public String EXPIRATION_DATE;
public String START_AZ;
ZekrDataSource datasource;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//PreferenceActivity is a subclass of ListActivity (source), so you can either remove the setContentView() method call or add a subview with id android.R.list in added_zekr_view.xml
//I removed setContentView(R.layout.added_zekr_view);
//setContentView(R.layout.added_zekr_view);
datasource=new ZekrDataSource(this);
datasource.open();
List<AddedZekrView> addedZekrFields2 = datasource.getAllRecordList();
// if this is first time that we run App so maybe we dont have any data on it so we need to check that
//And call our list View again
if (addedZekrFields2.size()==0) {
Toast toast = Toast.makeText(this, "Nothing Founded.",Toast.LENGTH_LONG);
toast.show();
//datasource.insertRecord(null, null, null, null, null, null);
addedZekrFields2 = datasource.getAllRecordList();
}
ArrayAdapter<AddedZekrView> adapter = new ArrayAdapter<AddedZekrView>(this, android.R.layout.simple_expandable_list_item_1, addedZekrFields2 );
setListAdapter(adapter);
}
}
Can someone please help me to figure it out.
Thank you so much.

I Overwrite toString() and it solve my problem :)

Related

Get and select contacts in android

I'm trying get all contacts and select it.
I completed get all contacts in my phone. But when i try to select a few contacts and get their names or numbers, I faced nullpointer error.
public class ContactListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
private CursorAdapter mAdapter;
final HashMap<String,String> hashMap = new HashMap<String,String>();
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
private Uri uriContact;
private String contactID;
String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// create adapter once
Context context = getActivity();
int layout = android.R.layout.simple_list_item_multiple_choice;
Cursor c = null; // there is no cursor yet
int flags = 0; // no auto-requery! Loader requeries.
mAdapter = new SimpleCursorAdapter(context, layout, c, FROM, TO, flags);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// each time we are started use our listadapter
setListAdapter(mAdapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
// and tell loader manager to start loading
getLoaderManager().initLoader(0, null, this);
***getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursorID = getActivity().getContentResolver().query(uriContact,
new String[]{ContactsContract.Contacts._ID},
null, null, null);
contactID = cursorID.getString(cursorID.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(contactID);
}
});
}***
// columns requested from the database
private static final String[] PROJECTION = {
Contacts._ID, // _ID is always required
Contacts.DISPLAY_NAME_PRIMARY // that's what we want to display
};
// and name should be displayed in the text1 textview in item layout
private static final String[] FROM = { Contacts.DISPLAY_NAME_PRIMARY };
private static final int[] TO = { android.R.id.text1 };
#Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// load from the "Contacts table"
Uri contentUri = Contacts.CONTENT_URI;
// no sub-selection, no sort order, simply every row
// projection says we want just the _id and the name column
return new CursorLoader(getActivity(),
contentUri,
PROJECTION,
null,
null,
null);
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// Once cursor is loaded, give it to adapter
mAdapter.swapCursor(data);
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
// on reset take any old cursor away
mAdapter.swapCursor(null);
}
I think problem is my onItemClickListener.
How can i fix this?
Thanks from now :)
The main problem is that uriContact is null when you make the query.
The other problem is that you are only using ContactsContract.Contacts._ID as the projection, so the ID is the only thing returned.
I got it working by using null for the projection so that it returns all rows.
I also added functionality to find the currently selected contact, and display a Toast with their phone number.
This is not optimal code, since it just queries all rows and then iterates through them until it finds the currently selected contact, but it works:
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cur = mAdapter.getCursor();
cur.moveToPosition(position);
String curName = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
System.out.println(curName);
uriContact = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor cursorID = getContentResolver().query(uriContact,
null,
null, null, null);
for (cursorID.moveToFirst(); !cursorID.isAfterLast(); cursorID.moveToNext() ) {
String testName = cursorID.getString(cursorID.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
if (testName != null && testName.equals(curName)) {
contactID = cursorID.getString(cursorID.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
}
if (contactID != null) {
System.out.println(contactID);
Toast.makeText(MainActivity.this, "contact Phone: " + contactID, Toast.LENGTH_LONG).show();
}
}
});
Edit: I got a more optimized version working, which uses the selection and selectionArgs in the query to return just the current contact info:
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cur = mAdapter.getCursor();
cur.moveToPosition(position);
String curName = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
System.out.println(curName);
uriContact = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor cursorID = getContentResolver().query(uriContact,
null,
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + " = ?", new String[]{curName}, null);
if (cursorID.moveToFirst()) {
contactID = cursorID.getString(cursorID.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
if (contactID != null) {
System.out.println(contactID);
Toast.makeText(MainActivity.this, "contact Phone: " + contactID, Toast.LENGTH_LONG).show();
}
}
});

I'm getting object data output from sqlite instead of the data I need

I'm getting object data returned from my code here, but I don't see how I can be doing that.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage);
Log.d(TAG, "onCreate");
datasource = new DataSource(this);
datasource.open();
List<Encouragement> values = datasource.getAllEncouragements();
Log.d(TAG, "values");
ArrayAdapter<Encouragement> adapter = new ArrayAdapter<Encouragement>(this,
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
Log.d(TAG, "end of onCreate");
}
and
public List<Encouragement> getAllEncouragements() {
List<Encouragement> encouragements = new ArrayList<Encouragement>();
Cursor cursor = database.query(DatabaseHelper.TABLE_ENCOURAGEMENTS,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Encouragement encouragement = cursorToEncouragement(cursor);
encouragements.add(encouragement);
cursor.moveToNext();
}
cursor.close();
return encouragements;
}
is producing com.example.myActivity.myObject#34563475 in the list item.
The listview is calling toString() to represent myObject. You have not overridden the toString() method hence the default Object.toString() method is called.
#Override
public String toString(){
return this.name; // whatever you need to represent this instance of myObject.
}

Android IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase [duplicate]

This question already has an answer here:
attempt to re-open an already-closed object: SQLiteDatabase
(1 answer)
Closed 8 years ago.
I know there are several questions like this one, but all of them seem to have a different approach to solve the problem and none have solved mine.
I have my main activity working just fine, loading the db and populating the listview. Then I call a second activity and the problem shows up when I try to load the listview.
I have tried using start/stop managingcursor(cursor) even though it is deprecated, but it didn't fix the problem. Also I tried cloasing the cursor and db in my main activity before firing the next one but that didn't help either.
Both classes extend from ListActivity and follow the same sequence:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Open db in writing mode
MySQLiteHelper.init(this);
MySQLiteHelper tpdbh =
new MySQLiteHelper(this, "DB", null, 1);
SQLiteDatabase db = tpdbh.getWritableDatabase();
checkLocationAndDownloadData(); //this fires a Asynctask that calls method parseNearbyBranches shown bellow
//I load the data to the ListView in the postExecute method of the asynctask by calling:
/*
Cursor cursor = MysSQLiteHelper.getBranchesNames();
adapter = new SimpleCursorAdapter(this,
R.layout.row, cursor, fields, new int[] { R.id.item_text },0);
setListAdapter(adapter);
*/
ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
// Get the cursor, positioned to the corresponding row in the result set
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
// Get the state's capital from this row in the database.
String branch_id = cursor.getString(cursor.getColumnIndexOrThrow("branch_id"));
cursor.close();
openNextActivity(Integer.parseInt(branch_id));
}
});
}
//In another file:
private void parseNearbyBranches(JSONObject jo) throws JSONException
{
if ( jo.has(jsonTitle) &&
jo.has("company_id") &&
jo.has("id")
) {
String branch = jo.getString(jsonTitle);
MySQLiteHelper tpdbh = MySQLiteHelper.instance;
SQLiteDatabase db = tpdbh.getWritableDatabase();
db.execSQL("INSERT INTO Branches (branch_id, name, company_id) " +
"VALUES ('" +jo.getInt("id")+"', '" + branch +"', '" +jo.getInt("company_id")+"' )");
db.close(); //no difference is I comment or uncomment this line
}
}
In MySQLiteHelper.java:
public static Cursor getBranchesNames() {
// TODO Auto-generated method stub
String[] columns = new String[] { "_id", "branch_id", "name", "company_id" };
Cursor c = getReadDb().query(branchesTable, columns, null, null, null, null,
null);
return c;
}
My other activity does basically the same:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_branch_surveys);
//Read branch data from DB
int companyID = -1;
MySQLiteHelper.init(this);
String [] columns = new String [] {"company_id"};
String [] args = {Integer.toString(branchID)};
Cursor c = MySQLiteHelper.getReadDb().query(MySQLiteHelper.branchesTable, columns, "branch_id=?", args, null, null, null); //THIS QUERY WORKS JUST FINE
if (c.moveToFirst())
companyID = Integer.parseInt(c.getString(0));
c.close();
if( companyID != -1)
{
new DownloadTask().execute(Integer.toString(companyID) );
//where the Async task calls something just like NearByBranches shown above(but with different objects of course)
//And the postExecute sets the listView:
/* cursor = MySQLiteHelper.getAll();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.row, cursor, fields, new int[] { R.id.item_text },0);
setListAdapter(adapter);
*/
}
}
}
In MySQLiteHelper.java:
public static Cursor getAll() {
// TODO Auto-generated method stub
String[] columns = new String[] { "_id","title", "points" };
//********IT IS IN THIS LINE WHERE I GET THE ERROR:********************
Cursor c = getReadDb().query(theTable, columns, null, null, null, null,
null);
return c;
}
public static SQLiteDatabase getReadDb() {
if (null == db) {
db = instance.getReadableDatabase();
}
return db;
}
I hope you can help me out. Thanks!
I just tried commenting the db.close in the similar method of parseNeabyBranches and the problem was solved. Yet I dont get the same error having db.close() in parseNearbyBranches(), can you explain me why?
In parseNearbyBranches() you create a separate SQLiteDatabase object with:
SQLiteDatabase db = tpdbh.getWritableDatabase();
Since this is a different object than the one returned by getReadDb(), you can (and should) close it. The basic rule is each time you call getWritableDatabase() and getReadableDatable() you must have a matching close() statement.

Android: I have to display content from the database in the listview, in which latest data comes on top

I have to implement a listview in which my current data comes on top of the listview. Right now my recent data comes at the bottom and my first data is coming on the top of the listview. I'm attaching my work so far:
SearchActivity.java
public class SearchActivity extends Activity implements OnClickListener,
OnItemClickListener {
private EditText mHistoryNameEditText;
private Button mInsertButton;
private ListView mHistoryListView;
private ListAdapter mHistoryListAdapter;
private ArrayList<SearchHistoryDetails> searchArrayList;
private ArrayList<SearchHistoryDetails> HistoryObjArrayList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHistoryNameEditText = (EditText) findViewById(R.id.editText1);
mInsertButton = (Button) findViewById(R.id.button1);
mInsertButton.setOnClickListener(this);
mHistoryListView = (ListView) findViewById(R.id.names_lsitviews);
mHistoryListView.setOnItemClickListener(this);
searchArrayList = new ArrayList<SearchHistoryDetails>();
mHistoryListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, populateList());
mHistoryListView.setAdapter(mHistoryListAdapter);
HistoryObjArrayList = new ArrayList<SearchHistoryDetails>();
}
#Override
public void onClick(View v) {
if (v.getId() == R.id.button1) {
String providedUgraduateName = mHistoryNameEditText.getText()
.toString();
SearchHistoryDetails undergraduateDetailsPojoObj = new SearchHistoryDetails();
undergraduateDetailsPojoObj.setuGraduateName(providedUgraduateName);
HistoryObjArrayList.add(undergraduateDetailsPojoObj);
insertUndergraduate(undergraduateDetailsPojoObj);
finish();
}
}
public void insertUndergraduate(
SearchHistoryDetails paraUndergraduateDetailsPojoObj) {
AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(
this);
SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj
.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME,
paraUndergraduateDetailsPojoObj.getuGraduateName());
long affectedColumnId = sqliteDatabase.insert(
AndroidOpenDbHelper.TABLE_NAME_GPA, null, contentValues);
sqliteDatabase.close();
Toast.makeText(this,
"Values inserted column ID is :" + affectedColumnId,
Toast.LENGTH_SHORT).show();
}
public List<String> populateList() {
List<String> uGraduateNamesList = new ArrayList<String>();
AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);
SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
Cursor cursor = sqliteDatabase.query(
AndroidOpenDbHelper.TABLE_NAME_GPA, null, null, null, null,
null, null);
startManagingCursor(cursor);
while (cursor.moveToNext()) {
String ugName = cursor
.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME));
SearchHistoryDetails ugPojoClass = new SearchHistoryDetails();
ugPojoClass.setuGraduateName(ugName);
searchArrayList.add(ugPojoClass);
uGraduateNamesList.add(ugName);
}
sqliteDatabase.close();
return uGraduateNamesList;
}
#Override
protected void onResume() {
super.onResume();
searchArrayList = new ArrayList<SearchHistoryDetails>();
mHistoryListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, populateList());
mHistoryListView.setAdapter(mHistoryListAdapter);
}
#Override
protected void onStart() {
super.onStart();
searchArrayList = new ArrayList<SearchHistoryDetails>();
mHistoryListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, populateList());
mHistoryListView.setAdapter(mHistoryListAdapter);
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getApplicationContext(), "Clicked on :" + arg2,
Toast.LENGTH_SHORT).show();
SearchHistoryDetails clickedObject = searchArrayList.get(arg2);
Bundle dataBundle = new Bundle();
dataBundle.putString("clickedUgraduateName",
clickedObject.getuGraduateName());
}}
This class helps me in getting the data from the database and populating it on the activity. My creating database class:
AndroidOpenDbHelper.java
public class AndroidOpenDbHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "allsearch_history_db";
public static final int DB_VERSION = 1;
public static final String TABLE_NAME_GPA = "search_table";
public static final String COLUMN_NAME_UNDERGRADUATE_NAME = "undergraduate_name_column";
public AndroidOpenDbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
String sqlQueryToCreateUndergraduateDetailsTable = "create table if not exists "
+ TABLE_NAME_GPA
+ " ( "
+ BaseColumns._ID
+ " integer primary key autoincrement, "
+ COLUMN_NAME_UNDERGRADUATE_NAME
+ " text not null); ";
db.execSQL(sqlQueryToCreateUndergraduateDetailsTable);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 1 && newVersion == 2) {
// Upgrade the database
}
}}
This is the class from which I create database and table.
Now, the real deal is that, when I try to populate data from the database it comes as the first one on top and the latest one on down. I want to revert it. Any help will be appreciated in overcoming this problem.
There are a few different ways to do this. I recommend using the ORDER BY clause of your query:
Cursor cursor = sqliteDatabase.query(
AndroidOpenDbHelper.TABLE_NAME_GPA, null, null, null, null, null,
AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME + " DESC");
Also if you are only going to read from one column, your query should only request that column. Otherwise you are wasting resources querying unused columns of information:
Cursor cursor = sqliteDatabase.query(
AndroidOpenDbHelper.TABLE_NAME_GPA,
new String[] {AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME},
null, null, null, null,
AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME + " DESC");
Lastly, you may want to look into using a SimpleCursorAdapter which allows you to bind a query to a ListView with minimal code.
Addition
I took a closer look at your code and try this:
Cursor cursor = sqliteDatabase.query(
AndroidOpenDbHelper.TABLE_NAME_GPA, null, null, null, null, null,
BaseColumns._ID + " DESC");
Well i can suggest you to get the data from the database and add the items in the reverse order in the adapter that you are setting for populating the listview.
Consider this as the sample where you can get the values from the database which returns an arraylist.
Now consider this arraylist and add each item to the arrayadapter from the last like :
for(i=arraylist.size()-1;i>0;i--)
{
adapter.add(arraylist.get(i));
}
and after setting for the first time you can call
adapter.notifyDataSetChanged()
to refresh the list automatically.
Give a try to this

How to get values to listview or tableview from database in Android?

I have database called wisherDB, and I have a table called tbltasks inside the database.
The Table simply has colmmn names of id, title, name, date, time, and type. I want to get id, name, and the time to relate to the current date, and I can access current date by a Calendar class, so that is not the problem.
The selection code is in a seperate class called DataAccess and code is mentioned below.
What I want to do is get the details from the query and display it on the tableview. I tried this without selection of date[where clause][that means select * from ...] that is working for this.
But with the selection, it's not showing the data.
DatabaseAccess class Select query:
public Cursor getTasktoDate(String Date) throws SQLException
{
Cursor mCursor=db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,KEY_TASKNAME,KEY_TASKTYPE}, KEY_TASKDATE+"="+ Date, null, null, null, null, null);
if(mCursor!=null)
{
mCursor.moveToFirst();
}
return mCursor;
}
And this is the code of the activity:
Cursor c=dba.getTasktoDate("2011/10/12");
if (c.moveToFirst())
{
do {
DisplayContact(c, tltodaytask);
} while (c.moveToNext());
}
dba.Close();
}
private void DisplayContact(Cursor c, TableLayout tltodaytask) {
// TODO Auto-generated method stub
String id=c.getString(0);
String tName=c.getString(1);
String tType=c.getString(2);
insertRow(tltodaytask,id,tName,tType);
}
private void insertRow(TableLayout tltodaytask, String id, String tName,
String tType) {
// TODO Auto-generated method stub
final TableRow newrow = new TableRow(this);
addTexttoRowswithValues(newrow, id);
addTexttoRowswithValues(newrow, tName);
addTexttoRowswithValues(newrow, tType);
tltodaytask.addView(newrow);
}
private void addTexttoRowswithValues(TableRow newrow, String text) {
// TODO Auto-generated method stub
TextView textview = new TextView(this);
textview.setWidth(115);
textview.setText(text);
newrow.addView(textview);
}
This method not working.
You have problem in
Cursor mCursor=db.query(true, DATABASE_TABLE,
new String[] {KEY_ROWID,KEY_TASKNAME,KEY_TASKTYPE},
KEY_TASKDATE+"="+ Date, null, null, null, null, null);
You should use
Cursor mCursor=db.query(true, DATABASE_TABLE,
new String[] {KEY_ROWID,KEY_TASKNAME,KEY_TASKTYPE},
KEY_TASKDATE+"= ?", new String[]{Date}, null, null, null, null);

Categories

Resources