cannot be cast to android.database.Cursor - android

I want get info Object in row item ListView ..listview load info in database..
add Income
public void addIncome(OIncome income) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TABLE_INCOME_COLUMN_NAME, income.get_name());
values.put(TABLE_INCOME_COLUMN_CATEGORY, income.get_category() + 1);
values.put(TABLE_INCOME_COLUMN_AMOUNT, income.get_amount());
values.put(TABLE_INCOME_COLUMN_DATE, income.get_date());
values.put(TABLE_INCOME_COLUMN_TIME, income.get_time());
values.put(TABLE_INCOME_COLUMN_NOTE, income.get_note());
db.insert(TABLE_INCOME, null, values);
db.close();
}
Get Income
public List<OIncome> getIncome() {
List<OIncome> list = new ArrayList<OIncome>();
String selectIncome = "SELECT * FROM " + TABLE_INCOME + " INNER JOIN "
+ TABLE_CATEGORY + " ON " + TABLE_CATEGORY + "."
+ TABLE_CATEGORY_COLUMN_ID + "=" + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_CATEGORY + " WHERE " + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_DATE + "=" + "'" + GET_DATE + "'"
+ " ORDER BY " + TABLE_INCOME + "." + TABLE_INCOME_COLUMN_DATE
+ " DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectIncome, null);
if (cursor.moveToFirst()) {
do {
OIncome income = new OIncome();
income.set_amount(cursor.getFloat(3));
income.set_category(cursor.getInt(8));
income.set_name(cursor.getString(1));
income.set_date(cursor.getString(4));
income.set_time(cursor.getString(5));
list.add(income);
} while (cursor.moveToNext());
}
return list;
}
in class ListIncomeAdapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(layout, null);
}
OIncome income = list.get(position);
TextView tvnameincome = (TextView) convertView
.findViewById(R.id.tvnameincome);
TextView tvdateincome = (TextView) convertView
.findViewById(R.id.tvdateincome);
TextView tvtimeincome = (TextView) convertView
.findViewById(R.id.tvtimeincome);
TextView tvamountincome = (TextView) convertView
.findViewById(R.id.tvamountincome);
ImageView imglistincome = (ImageView) convertView
.findViewById(R.id.imglistincome);
Other other = new Other();
// OCatergory catergory = data.get(position);
tvnameincome.setText(income.get_name());
tvdateincome.setText(other.convertDateYear(income.get_date()));
tvtimeincome.setText(income.get_time());
tvamountincome.setText(income.get_amount() + "");
imglistincome.setImageResource(income.get_category());
return convertView;
}
How can I get the information of that item..
please give me a few lines of
get information on that item

You have to extract it from the parent, like below. I'm not 100% sure on the syntax though, because I don't have my Android workspace here.
OIncome income = (OIncome) ((ListView) parent).getItemAtPosition(position);
This replaces your line of code, which throws the Cast Exception:
OIncome income = list.get(position);

Related

ListView displaying 5 times the same line

I created an adapter for my ListView that's displaying a data from my SQLite database, the problem is that in the ListView, I have 5 times the same line:
My adapter's code:
public class MyAdapter extends ArrayAdapter<Historique> {
private LayoutInflater mInflat;
private ArrayList<Historique> hist = new ArrayList<Historique>();
private int mVRessId;
public MyAdapter (Context context, int ressId, ArrayList<Historique> hists){
super(context,ressId,hists);
this.hist =hists;
mInflat = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mVRessId =ressId;
}
public View getView(int position, View convertedView, ViewGroup parents){
convertedView = mInflat.inflate(mVRessId,null);
Historique histor = hist.get(position);
if (histor != null){
TextView name = (TextView) convertedView.findViewById(R.id.hnom);
TextView quest = (TextView) convertedView.findViewById(R.id.hques);
TextView rep = (TextView) convertedView.findViewById(R.id.hrep);
TextView date = (TextView) convertedView.findViewById(R.id.hdate);
if (name != null){
name.setText(""+histor.getNom()+ ": "+histor.getLigne());
}
if (quest != null){
quest.setText(histor.getQuest());
}
if (rep != null){
rep.setText(histor.getRep());
}
if (date != null){
date.setText(histor.getDate().toString());
}
}
return convertedView;
}
}
The ListView must display the list, and here's the code:
final MyAdapter adapter = new MyAdapter (this, R.layout.adapter_view_layout,histList);
mCsr = openhelper.getTableHistoAsCursor();
int rows = mCsr.getCount();
if (rows == 0 ){
Toast.makeText(Historian.this, "Pas d'historique disponible", Toast.LENGTH_SHORT).show();
} else {
while (mCsr.moveToNext()){
histo = new Historique(mCsr.getString(0).toString(),mCsr.getString(1).toString(), mCsr.getString(2).toString(),mCsr.getString(3).toString(),mCsr.getString(4).toString());
histList.add(histo);
}
}
mListView .setAdapter(adapter);
The getTableHisto is a function that returns a cursor from my SQLite Modelhelper:
public Cursor getTableHistoAsCursor() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor data = db.rawQuery(" SELECT Q." + KEY_QUESTION + " ,L." + KEY_LIGNE + " , U." + KEY_NOM + " , A." + KEY_DATE + " , A. " + KEY_REPONSE + " from "+ TABLE_LIGNE + " L, " + TABLE_QUESTION + " Q, " + TABLE_USER + " U, " + TABLE_ANSWER + " A WHERE Q." + KEY_ID_QUESTION + " = A." + KEY_ID_QUESTION + " AND A." + KEY_MATRICULE + " = U." + KEY_MATRICULE, null);
return data;
}
In the first time, I thought that in the insert I was doing something wrong and it goes 5 times in the database, so I've created an activity to try to get the number of inserts with a Select count();
And I saw that the result that I'm getting is the true result, I don't insert 5 times the same line, but the adapter is displaying it 5 times in 5 lines.
If you have any idea that can help me, I would be thankful.
thanks.
//Initialize my adapter after populating the list
histList.add(histo);
Adapter is only initialized after populating values in the Array List
not with null values.
final MyAdapter adapter = new MyAdapter (this, R.layout.adapter_view_layout,histList);
mListView .setAdapter(adapter);
I got it, the problem is solved, in case someone has the same problem, the loop wasn't good so I changed
else {
while (mCsr.moveToNext()){
by
else {
if (mCsr != null){
mCsr.moveToFirst();

The List having duplicate data when I using left outer join in query

This is how I display my listView, but when I display using this kind of method it gives me duplicate data. I think this is because my "CondimentDescription" will have more than 1 data. The following is my code:
public List<OrderList> getOrderList() {
List<OrderList> OrderList = new ArrayList<OrderList>();
OrderList list = new OrderList();
try {
String selectQuery = "select t2.Id,t2.ProductCode,t2.Price,t2.Qty,t3.Description,t4.condimentDescription from TempCS t1 \n" +
"left outer join TempCSDetail t2 on t1.DocNo=t2.Docno\n" +
"left outer join mProduct t3 on t2.ProductCode=t3.Code \n" +
"left outer join TempCSCondiment t4 on t2.SeqNo=t4.SeqNo"+
"where t1.DocNo=" + TablePageDocNo + "\n";
SQLiteDatabase db1 = db.getReadableDatabase();
Cursor cursor = db1.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
list.setProductCode(cursor.getString(cursor.getColumnIndex("ProductCode")));
list.setPrice(Double.parseDouble(cursor.getString(cursor.getColumnIndex("Price"))));
list.setQty(cursor.getString(cursor.getColumnIndex("Qty")));
list.setDescription(cursor.getString(cursor.getColumnIndex("Description")));
list.set_ID(Integer.parseInt(cursor.getString(cursor.getColumnIndex("ID"))));
//this will more than 1 row in my Sqlite database
list.setCondimentDescription(cursor.getString(cursor.getColumnIndex("CondimentDescription")));
OrderList.add(list);
} while (cursor.moveToNext());
}
}catch(Exception e){
}
return OrderList;
}
Adapter List
public class OrderListAdapter extends BaseAdapter {
LayoutInflater mInflater;
public OrderListAdapter() {
mInflater = LayoutInflater.from(ListFragmentActivity.this);
}
#Override
public int getCount() {
return orderlist.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listproduct1, null);
}
final TextView _ID = (TextView) convertView.findViewById(R.id.proID);
_ID.setText("" + orderlist.get(position).get_ID());
final String proID = _ID.getText().toString();
final TextView ProductCode = (TextView) convertView.findViewById(R.id.productcode);
ProductCode.setText("" + orderlist.get(position).getProductCode());
final TextView Description = (TextView) convertView.findViewById(R.id.description);
Description.setText("" + orderlist.get(position).getDescription());
final TextView Price = (TextView) convertView.findViewById(R.id.price);
Price.setText("" + String.format("%.2f",orderlist.get(position).getPrice()));
final Double price= Double.valueOf(Price.getText().toString());
final TextView Qty = (TextView) convertView.findViewById(R.id.qty);
Qty.setText("" + orderlist.get(position).getQty());
final TextView condimentDescription=(TextView)convertView.findViewById(R.id.condimentDescription);
condimentDescription.setText("" + orderlist.get(position).getCondimentDescription());
notifyDataSetChanged();
return convertView;
}
}
quickly look at your code :
"left outer join TempCSCondiment t4 on t2.SeqNo=t2.SeqNo"+
It might goes wrong here. you want to join t4, but the on clause :
t2.SeqNo=t2.SeqNo"
And I suppose that your data is not duplicated ( and you know the result of different kind of join type).
You should give same column name in getColumnIndex() method as in Database.
Try this:
public List<OrderList> getOrderList() {
SQLiteDatabase db1 = db.getReadableDatabase();
String selectQuery = "select t2.Id,t2.ProductCode,t2.Price,t2.Qty,t3.Description,t4.condimentDescription from TempCS t1 \n" +
"left outer join TempCSDetail t2 on t1.DocNo=t2.Docno\n" +
"left outer join mProduct t3 on t2.ProductCode=t3.Code \n" +
"left outer join TempCSCondiment t4 on t2.SeqNo=t2.SeqNo"+
"where t1.DocNo=" + TablePageDocNo + "\n";
Cursor cursor = db1.rawQuery(selectQuery, null);
List<OrderList> OrderList = new ArrayList<OrderList>();
OrderList list = new OrderList();
try {
if (cursor.moveToFirst()) {
do {
list.setProductCode(cursor.getString(cursor.getColumnIndex("ProductCode")));
list.setPrice(Double.parseDouble(cursor.getString(cursor.getColumnIndex("Price"))));
list.setQty(cursor.getString(cursor.getColumnIndex("Qty")));
list.setDescription(cursor.getString(cursor.getColumnIndex("Description")));
list.set_ID(Integer.parseInt(cursor.getString(cursor.getColumnIndex("Id"))));
//this will more than 1 row in my Sqlite database
list.setCondimentDescription(cursor.getString(cursor.getColumnIndex("condimentDescription")));
OrderList.add(list);
} while (cursor.moveToNext());
}
}catch(Exception e){
}
return OrderList;
}

How to check values in HashMap<String, String> and setBackgroundResource when record = value?

I have just started coding an Android App using Android Studio 2.1 and my app was sort of an offline messaging - this is using SQLite Database (basically compose of two tables message and contact).
I am now in my last activity where I need to populate a list of message exchange from the contacts created. I was able to list them but without aesthetics. I would like to set different setBackgroundResource whenever the type is either a LEFT or RIGHT but was struggling to apply it.
Below is my code:
MessageRepo - the SQLite DBhelper:
public ArrayList<HashMap<String, String>> getMessageListById(int fromid, int toid) {
SQLiteDatabase db = helper.getWritableDatabase();
String toquery = "SELECT " + MessageModel.messageId +
", " + MessageModel.fromId +
", " + MessageModel.toId +
", " + MessageModel.messageContent +
", 'RIGHT' AS type FROM " + MessageModel.tableMessage +
" WHERE " + MessageModel.toId +
" = ? AND " + MessageModel.fromId +
" = ? ";
String fromquery = "SELECT " + MessageModel.messageId +
", " + MessageModel.fromId +
", " + MessageModel.toId +
", " + MessageModel.messageContent +
", 'LEFT' AS type FROM " + MessageModel.tableMessage +
" WHERE " + MessageModel.fromId +
" = ? AND " + MessageModel.toId +
" = ? ";
String query = toquery +
" UNION " + fromquery +
" ORDER BY " + MessageModel.messageId;
ArrayList<HashMap<String, String>> messageList = new ArrayList<HashMap<String, String>>();
Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(fromid), String.valueOf(toid), String.valueOf(fromid), String.valueOf(toid)});
if (cursor.moveToFirst()) {
do {
HashMap<String, String> messages = new HashMap<String, String>();
messages.put("messageId", cursor.getString(0));
messages.put("messageFromId", cursor.getString(1));
messages.put("messageToId", cursor.getString(2));
messages.put("messageContent", cursor.getString(3));
messages.put("type", cursor.getString(4));
messageList.add(messages);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return messageList;
}
Message Activity - this will display in a ListView but not working as I was intending it to display:
ArrayList<HashMap<String, String>> messageList = messagehandler.getMessageListById(_fromid, _toid);
if (messageList.size() != 0) {
ListView listView = getListView();
if(messageList.contains("RIGHT")) {
listView.setBackgroundResource(R.drawable.right);
} else {
listView.setBackgroundResource(R.drawable.left);
}
ListAdapter adapter = new SimpleAdapter(MessageDetailActivity.this, messageList, R.layout.message, new String[]{"messageFromId", "messageToId", "messageContent"}, new int[]{R.id.FromId, R.id.ToId, R.id.message});
setListAdapter(adapter);
}
I've checked a lot of posts and I can't seem to make it work for me:
The constructor ArrayAdapter>>(Context, int, ArrayList>) is undefined
Android Alternate row Colors in ListView
Thanks a lot in advance!
After researching a bit more. I finally found the answer by opting to use List and a setter/getter class:
public class MessagesAdapter extends ArrayAdapter<ContactsAndMessages> {
public MessagesAdapter(Context context, List<ContactsAndMessages> contacts) {
super(context, 0, contacts);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ContactsAndMessages contact = getItem(position);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica.ttf");
if(convertView == null) {
if (contact.type.equalsIgnoreCase("me")) {....

Multi-Dimensional Checkbox array in android

Am trying to create dynamic checkboxes based on contents of two tables. I am able to create the checkboxes but the problem comes on the OnCheckedChangeListener where i cant pick the index of the clicked checkbox. Below is my code. Any assistance is highly appreciated
I call getViews() on the onCreate() Method
public void getViews(){
// TableLayout ref from xml where we want to Display list
final TableLayout proF = (TableLayout) findViewById(R.id.TableLayout_views);
// Get the database and run the query
final SQLiteDatabase datb = mDatabase.getWritableDatabase();
Cursor curs = datb.rawQuery("SELECT * FROM " + tarea.AREA_TABLE_NAME
+ " WHERE " + tarea.AREA_ID + " LIKE '" +"1"+ "' ", null);
curs.moveToFirst();
if (curs.getCount() > 0) {
for (int i = 0; i < curs.getCount(); i++) {
area_id = curs.getInt(curs.getColumnIndex(tarea.AREA_ID));
curs.moveToNext();
}
}
System.out.println("Area Id is : " + area_id);
Cursor cur = datb.rawQuery("SELECT * FROM " + tclass.CLASS_TABLE_NAME
+ " WHERE " + tclass.CLASS_AREA_ID + " LIKE '" +area_id+ "' ", null);
cur.moveToFirst();
clss = new String[cur.getCount()];
if (cur.getCount() > 0) {
int i ;
for (i = 0; i < cur.getCount(); i++) {
clss[i] = cur.getString(cur.getColumnIndex(tclass.CLASS_ITEM));
System.out.println("Class item : " + clss[i]);
class_id = cur.getInt(cur.getColumnIndex(tclass.CLASS_ID));
System.out.println("Class Id is : " + class_id);
Cursor c = datb.rawQuery("SELECT * FROM " + tmonitoring.MONITORING_TABLE_NAME
+ " WHERE " + tmonitoring.MONITORING_CLASS_ID + " LIKE '" +class_id+ "' ", null);
c.moveToFirst();
avail = new CheckBox[cur.getCount()][c.getCount()];
edtbox = new EditText[cur.getCount()][c.getCount()];
System.out.println("cur.getCount()>>" + cur.getCount());
System.out.println("c.getCount()>>" + c.getCount());
System.out.println("avail.length >> "+avail.length);
// class Dynamic table
TableRow RowArea = new TableRow(this);
TableRow tRow = new TableRow(this);
TableRow items = new TableRow(this);
int color = getResources().getColor(R.color.font_color_bg);
int color2 = getResources().getColor(R.color.font_color_white);
TextView tResult = new TextView(this);
tResult.setText("MON ITEM");
tResult.setTextColor(color2);
TextView tResult1 = new TextView(this);
tResult1.setText("_____________");
tResult1.setTextColor(Color.rgb(255, 106, 0));
TextView tResults = new TextView(this);
tResults.setText("RESULT");
tResults.setTextColor(color2);
TextView tResult2 = new TextView(this);
tResult2.setText("____________");
tResult2.setTextColor(Color.rgb(255, 106, 0));
TextView tResults1 = new TextView(this);
tResults1.setText("ACTION");
tResults1.setTextColor(color2);
TextView tResults2 = new TextView(this);
tResults2.setText("____________");
tResults2.setTextColor(Color.rgb(255, 106, 0));
TextView tResults3 = new TextView(this);
tResults3.setText("ACTION");
tResults3.setTextColor(color2);
TextView tResult3 = new TextView(this);
tResult3.setText("____________");
tResult3.setTextColor(Color.rgb(255, 106, 0));
TextView AreaResults = new TextView(this);
AreaResults.setBackgroundColor(color);
AreaResults.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);
AreaResults.setTextColor(color2);
AreaResults.setText(clss[i]);
RowArea.addView(AreaResults);
tRow.addView(tResult);
items.addView(tResult1);
tRow.addView(tResults);
items.addView(tResult2);
tRow.addView(tResults1);
items.addView(tResults2);
tRow.addView(tResults3);
items.addView(tResult3);
proF.addView(RowArea);
proF.addView(tRow);
proF.addView(items);
if (c.getCount() > 0) {
int j;
for (j = 0; j < c.getCount(); j++) {
System.out.println("Monitoring item : " + c.getString(c.getColumnIndex(tmonitoring.MONITORING_ITEM)));
TableRow newRow = new TableRow(this);
newRow.setGravity(Gravity.CENTER);
newRow.setTag(c.getString(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
// column 1 mon item
TextView nameCol = new TextView(this);
nameCol.setWidth(20);
nameCol.setMaxWidth(8);
nameCol.setTypeface(nameCol.getTypeface(), Typeface.BOLD);
nameCol.setText(" " + c.getString(c.getColumnIndex(tmonitoring.MONITORING_ITEM)));
//column 2 checkbox
CheckBox chkbox = new CheckBox(this);
chkbox.setId(j);
chkbox.setText("Yes");
avail[i][j] = chkbox;
System.out.println("avail["+i+"]["+j+"]>> " + chkbox);
System.out.println("avail id->" + avail[i][j].getId());
avail[i][j].setOnCheckedChangeListener(checkListener);
//column 3 take pic
Button picCol = new Button(this);
picCol.setText("Take Pic");
picCol.setTag(c.getInt(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
picCol.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SQLiteDatabase db = mDatabase.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "
+ shelfImage.IMAGE_TABLE_NAME + ";", null);
if (cursor.getCount() > 25) {
Log.v(TAG, "Alert SRR to upload data");
AlertDialog al = showAlertUpload();
al.show();
} else {
Intent myIntent = null;
myIntent = new Intent(Design_Template1.this, Capturephoto.class);
Bundle bund = new Bundle();
bund.putInt("r", r);
bund.putString("user", name);
bund.putInt("userid", userid);
bund.putString("dealer", dealer);
bund.putString("week", weekno);
bund.putString("ticket", Ticket);
bund.putString("picArray", picArray);
myIntent.putExtras(bund);
Design_Template1.this.startActivityForResult(myIntent, 0);
}
cursor.close();
db.close();
}
});
// column 4 view pic
Button viewCol = new Button(this);
viewCol.setText("View Guideline");
viewCol.setTag(c.getInt(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
viewCol.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Integer id = (Integer) v.getTag();
}
});
newRow.addView(nameCol);
newRow.addView(chkbox);
newRow.addView(picCol);
newRow.addView(viewCol);
proF.addView(newRow);
c.moveToNext();
}
}
c.close();
cur.moveToNext();
}
}
curs.close();
cur.close();
datb.close();
}
My click listener is as below
private OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
// Test avail Checkbox
StringBuffer r = new StringBuffer();
int clss;
db1 = mDatabase.getReadableDatabase();
System.out.println("area_id on click listener : " + area_id);
Cursor cur = db1.rawQuery("SELECT * FROM " + tclass.CLASS_TABLE_NAME
+ " WHERE " + tclass.CLASS_AREA_ID + " LIKE '" +area_id+ "' ", null);
cur.moveToFirst();
for(int i = 0; i < cur.getCount(); i++){
clss = cur.getInt(cur.getColumnIndex(tclass.CLASS_ID));
System.out.println("Classid on click listener : " + clss);
results = db1.rawQuery("SELECT "+tmonitoring.MONITORING_ITEM+" FROM " + tmonitoring.MONITORING_TABLE_NAME
+ " WHERE " + tmonitoring.MONITORING_CLASS_ID + " LIKE '" +clss+ "' ", null);
for (int u = 0; u < results.getCount(); u++) {
if (avail[u] != null) {
r.append("\nResults->" + u + " : ").append(
avail[i][u].isChecked());
}
}
cur.moveToNext();
}
cur.close();
results.close();
db1.close();
}
};
The part where i check if isChecked() throws ArrayIndexOutOfBoundsException. Please help
setting the tag will help you to recognize the created checkbox on later stage.
avail = new CheckBox[cur.getCount()][c.getCount()];
avail.setTag(i);//add this line
And inside
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
Integer i=(Integer)buttonView.getTag();
above line gets the checkbox on which the check/uncheck event is performed.
this way you would be able to find out the index.

Cursor Index Out of Bound

i trying to search in database whether the id is exist or not, when it exist i open the next activity , but when it not exist the app crash.. i coundnt find the bug , error Cursor Index out of bound
Database dbc = new Database(this);
dbc.open();
String id = searchId.getText().toString();
boolean checkId = dbc.isGotId(id);
if(checkId == true){
String s = searchId.getText().toString();
Bundle b = new Bundle();
b.putString("key",s);
b.putInt("keyX", radioBtnFlag);
Intent a = new Intent(SearchUpdate.this, UpdateDelete.class);
a.putExtras(b);
startActivity(a);
searchId.setText(null);
}else if(checkId == false){
Log.v(id, id + "2222222");
Dialog d = new Dialog(this);
d.setTitle("Error!");
TextView tv = new TextView(this);
tv.setText("This Search is allow only ID! "+ radioBtnFlag);
d.setContentView(tv);
d.show();
searchId.setText(null);
and here ...
public boolean isGotId(String id){
boolean result = false;
try{
Cursor sId = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Pro_ID + "=" + id, null);
result = true;
}catch(SQLiteException e)
{
result = false;
}//catch
return result;
}//isGOtId
Try this...
public boolean isGotId(String id){
Cursor sId = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " +
Pro_ID + "=" + id, null);
int numberOfRows = sId.getCount();
if(numberOfRows <= 0)
{
return false;
}
return true;
}
try{
Cursor sId = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Pro_ID + "=" + id, null);
if(sId.moveToFirst() && sId ! = null)
result = true;
}catch(SQLiteException e)
{
result = false;
}

Categories

Resources