Good day everyone. Can someone tell me how can I retrieve the data from SQLite to editText? I have referred to Android::Data are not retrieving to EditText field through Database but it not working for me..
DisplayData.java
private void BuildTable(String names,String date1)
{
final String name = names;
final String date=date1;
sqlcon.open();
Cursor c = sqlcon.readEntry(name);
int rows = c.getCount();
int cols = c.getColumnCount();
c.moveToFirst();
TableRow rowDayLabels=new TableRow(this);
TextView weather=new TextView(this);
weather.setText("Weather");
weather.setTypeface(Typeface.SERIF, Typeface.BOLD);
TextView dater=new TextView(this);
dater.setText("Date");
dater.setTypeface(Typeface.SERIF, Typeface.BOLD);
TextView status=new TextView(this);
status.setText("Status");
status.setTypeface(Typeface.SERIF, Typeface.BOLD);
TextView timeIn=new TextView(this);
timeIn.setText("Time In");
timeIn.setTypeface(Typeface.SERIF, Typeface.BOLD);
TextView timeOut=new TextView(this);
timeOut.setText("Time Out");
timeOut.setTypeface(Typeface.SERIF, Typeface.BOLD);
rowDayLabels.addView(weather);
rowDayLabels.addView(dater);
rowDayLabels.addView(status);
rowDayLabels.addView(timeIn);
rowDayLabels.addView(timeOut);
table_layout.addView(rowDayLabels);
// outer for loop
for (int i = 0; i < rows; i++) {
TableRow row = new TableRow(this);
row.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
// inner for loop
for (int j = 0; j < cols; j++) {
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
// tv.setBackgroundResource(R.drawable.cell_shape);
tv.setGravity(Gravity.CENTER);
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(c.getString(j));
row.addView(tv);
row.setBackgroundColor(Color.GREEN);
row.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(DisplayData.this, UpdatePage.class);
intent.putExtra("name", name);
intent.putExtra("date",date);
startActivity(intent);
}
});
}
c.moveToNext();
table_layout.addView(row);
}
sqlcon.close();
}
}
UpdateDetails.java
package com.example.project.project;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.example.project.project.API.InfoAPI;
import com.example.project.project.TimeSheet.Details;
import com.example.project.project.TimeSheet.Force;
import com.example.project.project.TimeSheet.Info;
import com.example.project.project.database.MyDatabaseHelper;
public class UpdatePage extends AppCompatActivity {
InfoAPI sqlcon;
private SQLiteDatabase database;
private MyDatabaseHelper dbHelper;
private Cursor c;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new MyDatabaseHelper(this);
setContentView(R.layout.updatepage);
final String name1 = getIntent().getExtras().getString("name");
final String date = getIntent().getExtras().getString("date");
RetrievePage(name1, date);
}
public void RetrievePage(String name, String date) {
final String name2 = name;
final String date2 = date;
final EditText name3 = (EditText) findViewById(R.id.editText9);
final EditText date3 = (EditText) findViewById(R.id.editText12);
name3.setText(name2);
date3.setText(date2);
//final Spinner weather3 = (Spinner) findViewById(R.id.spinner5);
//final Spinner status3 = (Spinner) findViewById(R.id.spinner7);
final EditText subC3 = (EditText) findViewById(R.id.editText17);
final EditText noP = (EditText) findViewById(R.id.editText18);
final EditText noH = (EditText) findViewById(R.id.editText19);
final Spinner poject3 = (Spinner) findViewById(R.id.spinner8);
database = dbHelper.getWritableDatabase();
c = database.rawQuery("SELECT w.Subcontractors, w.NumberOfPerson, w.NumberOfHours FROM Information i LEFT JOIN WorkForce w ON w.TInfo_id = i.ID WHERE i.Name = ? AND i.Date= ? ",
new String[]{String.valueOf(name2),String.valueOf(date2)}, null);
if (c != null) {
c.moveToFirst();
while (c.moveToNext()) {
Info I = new Info();
Details WD = new Details();
// String Weather = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Weather));
//String Status = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Status));
String SubC = c.getString(c.getColumnIndex(MyDatabaseHelper.Subcontractors));
String NoP = c.getString(c.getColumnIndex(MyDatabaseHelper.NumberOfPerson));
String NoH = c.getString(c.getColumnIndex(MyDatabaseHelper.NumberOfHours));
Force WF = new Force();
WF.setSubcontractors(SubC);
WF.setNoOfPerson(NoP);
WF.setNoOfHours(NoH);
subC3.setText(SubC);
noP.setText(NoP);
noH.setText(NoH);
}
}
c.close();
}
}
Force.java
public class Force {
private int id1;
private String subcontractors;
private String noOfPerson;
private String noOfHours;
public void setID(int id1)
{
this.id1=id1;
}
public int getID()
{
return this.id1;
}
public void setSubcontractors(String subcontractors)
{
this.subcontractors=subcontractors;
}
public String getSubcontractors()
{
return this.subcontractors;
}
public void setNoOfPerson(String noOfPerson)
{
this.noOfPerson=noOfPerson;
}
public String getNoOfPerson()
{
return this.noOfPerson;
}
public void setNoOfHours(String noOfHours)
{
this.noOfHours=noOfHours;
}
public String getNoOfHours()
{
return this.noOfHours;
}
}
Did I miss anything ? Please let me know! Any suggestions would be great. Thanks
If you are expecting only one row returned in the cursor you shouldn't call moveTofirst and moveToNext immediately before performing your operations. You are moving to the second row in the cursor by calling these functions immediately. My guess is that your cursor has only one row and your code in while loop is not being executed. Error might be here
if (c != null) {
c.moveToFirst();
while (c.moveToNext()) {
Info I = new Info();
}
}
You should be doing something like this
if (c != null) {
while (c.moveToNext()) {
Info I = new Info();
}
}
Related
I would like to update a single listview item and it works fine until I scroll down to items that are not visible and seems that there is an item (which was not visible) getting updated as well (I see this when I scroll down)
The image above describes the issue, when i update listview item in position 0, the item in position 5 (not visible until i scroll) also updates (it should not) and if i do the same for pos 1 then pos 6 is also updated and so on and so on even vice-versa, eg: when i update pos 7 and scroll up pos 2 will be updated as well, how can I prevent this and only have the listview update the item that i click on (and not update the listview item which is not visible until scroll)?
public class TestActivity extends ListActivity {
private SQLiteDatabase db;
private Cursor cursor;
private int correctAnswers;
private int incorrectAnswers;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
correctAnswers = 0;
incorrectAnswers = 0;
try{
DingDongDatabaseHelper coffeinaDatabaseHelper = new DingDongDatabaseHelper(this);
db = coffeinaDatabaseHelper.getReadableDatabase();
cursor = db.query("BPIE", new String[]{"_id", "QUESTION", "ANSWER1", "ANSWER2", "ANSWER3", "ANSWER4", "CORRECT"},null, null, null, null,null);
Random rand = new Random();
CursorAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.test_adapter, cursor, new String[]{ "QUESTION", "ANSWER1", "ANSWER2", "ANSWER3", "ANSWER4"}, new int[]{R.id.text_test_question, R.id.radio_answer1, R.id.radio_answer2, R.id.radio_answer3, R.id.radio_answer4}, 0);
}
setListAdapter(listAdapter);
}catch(SQLException e){
Toast toast = Toast.makeText(this, "Błąd",Toast.LENGTH_SHORT);
toast.show();
}
}
protected void onListItemClick(ListView l, View item, int position, long id) {
RadioButton radio1 = (RadioButton)item.findViewById(R.id.radio_answer1);
RadioButton radio2 = (RadioButton)item.findViewById(R.id.radio_answer2);
RadioButton radio3 = (RadioButton)item.findViewById(R.id.radio_answer3);
RadioButton radio4 = (RadioButton)item.findViewById(R.id.radio_answer4);
radio1.setBackgroundColor(Color.WHITE);
radio2.setBackgroundColor(Color.WHITE);
radio3.setBackgroundColor(Color.WHITE);
radio4.setBackgroundColor(Color.WHITE);
String correctAnswer="";
String selectedAnswer="";
if(item != null){
RadioGroup radioGroup = (RadioGroup)item.findViewById(R.id.radio_group);
RadioButton selectedButton = (RadioButton)item.findViewById(radioGroup.getCheckedRadioButtonId());
if(selectedButton!=null){
if(cursor.moveToPosition(position)) {
correctAnswer = cursor.getString(6);
}
selectedAnswer = String.valueOf(selectedButton.getText());
if(correctAnswer.equals(selectedAnswer)){
selectedButton.setBackgroundColor(Color.GREEN);
correctAnswers++;
}
else
{
incorrectAnswers++;
selectedButton.setBackgroundColor(Color.RED);
if(correctAnswer.equals(radio1.getText()))radio1.setBackgroundColor(Color.GREEN);
else if(correctAnswer.equals(radio2.getText()))radio2.setBackgroundColor(Color.GREEN);
else if(correctAnswer.equals(radio3.getText()))radio3.setBackgroundColor(Color.GREEN);
else if(correctAnswer.equals(radio4.getText()))radio4.setBackgroundColor(Color.GREEN);
}
Toast toast = Toast.makeText(TestActivity.this, "CORRECT: " + correctAnswer + "\nSELECTED: " + selectedAnswer, Toast.LENGTH_LONG);
toast.show();
}
}
}
}
Try this:
AnsweredQuestion.java:
public class AnsweredQuestion {
int selectedAnswerViewId;
int correctAnswerViewId;
public AnsweredQuestion(int selectedAnswerViewId, int correctAnswerViewId) {
this.selectedAnswerViewId = selectedAnswerViewId;
this.correctAnswerViewId = correctAnswerViewId;
}
}
TestActivity.java:
public class TestActivity extends ListActivity {
private SQLiteDatabase db;
private Cursor cursor;
private int correctAnswers;
private int incorrectAnswers;
private ArrayList<Integer> answeredQuestions = new ArrayList<>();
private HashMap<Integer, AnsweredQuestion> answeredQuestionHashMap = new HashMap<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
correctAnswers = 0;
incorrectAnswers = 0;
try{
DingDongDatabaseHelper coffeinaDatabaseHelper = new DingDongDatabaseHelper(this);
db = coffeinaDatabaseHelper.getReadableDatabase();
cursor = db.query("BPIE", new String[]{"_id", "QUESTION", "ANSWER1", "ANSWER2", "ANSWER3", "ANSWER4", "CORRECT"},null, null, null, null,null);
Random rand = new Random();
CursorAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.test_adapter, cursor, new String[]{ "QUESTION", "ANSWER1", "ANSWER2", "ANSWER3", "ANSWER4"}, new int[]{R.id.text_test_question, R.id.radio_answer1, R.id.radio_answer2, R.id.radio_answer3, R.id.radio_answer4}, 0){
#Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
int position = cursor.getPosition();
RadioButton radio1 = (RadioButton)view.findViewById(R.id.radio_answer1);
RadioButton radio2 = (RadioButton)view.findViewById(R.id.radio_answer2);
RadioButton radio3 = (RadioButton)view.findViewById(R.id.radio_answer3);
RadioButton radio4 = (RadioButton)view.findViewById(R.id.radio_answer4);
radio1.setBackgroundColor(Color.WHITE);
radio2.setBackgroundColor(Color.WHITE);
radio3.setBackgroundColor(Color.WHITE);
radio4.setBackgroundColor(Color.WHITE);
if(answeredQuestions.contains(position)){
AnsweredQuestion answeredQuestion = answeredQuestionHashMap.get(position);
RadioButton selectedAnswer = view.findViewById(answeredQuestion.selectedAnswerViewId);
RadioButton correctAnswer = view.findViewById(answeredQuestion.correctAnswerViewId);
selectedAnswer.setBackgroundColor(Color.RED);
correctAnswer.setBackgroundColor(Color.GREEN);
}
}
};
setListAdapter(listAdapter);
}catch(SQLException e){
Toast toast = Toast.makeText(this, "Błąd",Toast.LENGTH_SHORT);
toast.show();
}
}
protected void onListItemClick(ListView l, View item, int position, long id) {
RadioButton radio1 = (RadioButton)item.findViewById(R.id.radio_answer1);
RadioButton radio2 = (RadioButton)item.findViewById(R.id.radio_answer2);
RadioButton radio3 = (RadioButton)item.findViewById(R.id.radio_answer3);
RadioButton radio4 = (RadioButton)item.findViewById(R.id.radio_answer4);
radio1.setBackgroundColor(Color.WHITE);
radio2.setBackgroundColor(Color.WHITE);
radio3.setBackgroundColor(Color.WHITE);
radio4.setBackgroundColor(Color.WHITE);
String correctAnswer="";
String selectedAnswer="";
if(item != null){
RadioGroup radioGroup = (RadioGroup)item.findViewById(R.id.radio_group);
RadioButton selectedButton = (RadioButton)item.findViewById(radioGroup.getCheckedRadioButtonId());
RadioButton correctButton = null;
if(selectedButton!=null){
if(cursor.moveToPosition(position)) {
correctAnswer = cursor.getString(6);
}
selectedAnswer = String.valueOf(selectedButton.getText());
if(correctAnswer.equals(selectedAnswer)){
selectedButton.setBackgroundColor(Color.GREEN);
correctAnswers++;
correctButton = selectedButton;
}
else
{
incorrectAnswers++;
selectedButton.setBackgroundColor(Color.RED);
if(correctAnswer.equals(radio1.getText())) correctButton = radio1;
else if(correctAnswer.equals(radio2.getText())) correctButton = radio2;
else if(correctAnswer.equals(radio3.getText())) correctButton = radio3;
else if(correctAnswer.equals(radio4.getText())) correctButton = radio4;
correctButton.setBackgroundColor(Color.GREEN);
}
Toast toast = Toast.makeText(TestActivity.this, "CORRECT: " + correctAnswer + "\nSELECTED: " + selectedAnswer, Toast.LENGTH_LONG);
toast.show();
if(!answeredQuestions.contains(position)) answeredQuestions.add(position);
AnsweredQuestion answeredQuestion = new AnsweredQuestion(selectedButton.getId(), correctButton.getId());
answeredQuestionHashMap.put(position, answeredQuestion);
}
}
}
}
Hope that helps!
I have an SQLite database that is populated when the user create a profile and fill a form with his contact informations in SetUpProfile activity and then retrieve that data and show it back on UserProfile activity.
Question: How to display the profile data (name, phone, address...) in textviews ?
This is what I've done so far:
Profile class
public class Profile {
private int _id = 1;
private String _industryName;
private String _industryType;
private String _email;
private String _phone;
private String _address;
private String _packageType;
public Profile() {
/** stays empty */
}
public Profile(int _id, String _industryName, String _industryType, String _email, String _phone, String _address, String _packageType) {
this._id = _id;
this._industryName = _industryName;
this._industryType = _industryType;
this._email = _email;
this._phone = _phone;
this._address = _address;
this._packageType = _packageType;
}
public Profile(String _industryName, String _industryType, String _email, String _phone, String _address, String _packageType) {
this._industryName = _industryName;
this._industryType = _industryType;
this._email = _email;
this._phone = _phone;
this._address = _address;
this._packageType = _packageType;
}
//getters and setters
}
This is the handler DBHandler class
addProfile() method:
public void addProfile(Profile profile) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_INDUSTRY_NAME, profile.get_industryName());
values.put(KEY_INDUSTRY_TYPE, profile.get_industryType());
values.put(KEY_EMAIL, profile.get_email());
values.put(KEY_PHONE, profile.get_phone());
values.put(KEY_ADDRESS, profile.get_address());
values.put(KEY_PACKAGE_TYPE, profile.get_packageType());
// Inserting Row
db.insert(TABLE_PROFILE, null, values);
db.close();
}
getProfile() method
public Profile getProfile(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_PROFILE, new String[] {
KEY_ID, KEY_INDUSTRY_NAME, KEY_INDUSTRY_TYPE, KEY_EMAIL, KEY_PHONE, KEY_ADDRESS, KEY_PACKAGE_TYPE }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Profile profile = new Profile(
Integer.parseInt(cursor.getString(0)),
cursor.getString(1),
cursor.getString(2),
cursor.getString(3),
cursor.getString(4),
cursor.getString(5),
cursor.getString(6)
);
return profile;
}
MainActivity class
public class UserProfile extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
//SQLite databes is supposed to populate those textViews
industry_type = (TextView) findViewById(R.id.b_industry);
b_name = (TextView) findViewById(R.id.b_industry_name);
b_email = (TextView) findViewById(R.id.mail);
b_phone = (TextView) findViewById(R.id.phone);
b_address = (TextView) findViewById(R.id.address);
plan_type = (TextView) findViewById(R.id.p_title);
edit_profile = (Button) findViewById(R.id.editProfile);
industry_img = (ImageView) findViewById(R.id.thumbnail);
plan_img = (ImageView) findViewById(R.id.plan_icon);
edit_profile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
EditProfile();
}
});
}
This is the approach I used :
SQLiteDatabase db = null;
DBHandler dd = new DBHandler(getBaseContext());
dd.getWritableDatabase();
db= openOrCreateDatabase("profileManager.db", Context.MODE_PRIVATE, null);
Cursor cc = db.rawQuery("SELECT * FROM profile", null);
if(cc.getCount()>=1) {
cc.moveToFirst();
try {
for(int i=0;i < cc.getCount();i++){
bname = cc.getString(1);
btype = cc.getString(2);
bmail = cc.getString(3);
bphone = cc.getString(4);
baddress = cc.getString(5);
bpackage = cc.getString(6);
}
}catch (Exception e){
e.getMessage();
}
}
You need to create getters of your private variables of profile class. For example as below.
public String getIndustryName() {
return _industryName;
}
Then you need to call getProfile() method from your activity class which return Profile object.
From Profile object, you can get all value and set it into relevent TextView and display. For example as below.
b_name.setText(profile.getIndustryName());
I have an app that uses a foreign key when updating a table. I want to be able to put their email down instead of using their number.
Here is the Database methods:
private int getIdFromName(String email) {
SQLiteDatabase db = this.getWritableDatabase();
ArrayList<Integer> refs = new ArrayList<>();
Cursor cursor;
cursor = db.rawQuery("select " + REFEREE_EMAIL_COL + " from " +
REF_TABLE + " where " + REFEREE_EMAIL_COL + "='" + email + "'", null);
while (cursor.moveToNext()){
refs.add(cursor.getInt(0));
}
return refs.get(0);
}
public boolean updateRef(String email)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
int ref_id = getIdFromName(email);
values.put(REFEREE_ID_COL, ref_id);
db.insert(MATCH_TABLE, null, values);
return true;
}
Here is where I call it:
public class UpdateMatchActivity extends AppCompatActivity {
private static final String TAG = "EditDataActivity";
private Button btnSave,btnDelete;
private EditText homeTeamEdit, awayTeamEdit, typeOfMatchEdit, redCardsEdit, bookingsEdit, groundEdit, refEdit, dateEdit, timeEdit,
awayScoreEdit, homeScoreEdit;
DBHandler mDatabaseHelper;
private String homeTeam, awayTeam, homeScore, awayScore;
private String typeOfMatch;
private String ref;
private String redCards, bookings;
private String date, time;
private String ground;
private int selectedID;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_match);
btnSave = (Button) findViewById(R.id.UpdateMatchButton);
homeTeamEdit = (EditText) findViewById(R.id.HomeTeamUpdate);
homeScoreEdit = (EditText) findViewById(R.id.updateHomeScore);
awayTeamEdit = (EditText) findViewById(R.id.AwayTeamUpdate);
awayScoreEdit = (EditText) findViewById(R.id.updateAwayScore);
typeOfMatchEdit = (EditText) findViewById(R.id.updateTypeOfMatch);
refEdit = (EditText) findViewById(R.id.updateRef);
groundEdit = (EditText) findViewById(R.id.updateGround);
refEdit = (EditText) findViewById(R.id.updateRef);
ref = refEdit.getText().toString();
mDatabaseHelper = new DBHandler(this);
//get the intent extra from the ListDataActivity
Intent receivedIntent = getIntent();
//now get the itemID we passed as an extra
selectedID = receivedIntent.getIntExtra("MatchId", -1); //NOTE: -1 is just the default value
//now get the name we passed as an extra
homeTeam = receivedIntent.getStringExtra("homeTeam");
homeScore = receivedIntent.getStringExtra("homeScore");
awayTeam = receivedIntent.getStringExtra("awayTeam");
awayScore = receivedIntent.getStringExtra("awayScore");
ground = receivedIntent.getStringExtra("ground");
typeOfMatch = receivedIntent.getStringExtra("typeOfMatch");
//set the text to show the current selected name
homeTeamEdit.setText(homeTeam);
awayTeamEdit.setText(awayTeam);
typeOfMatchEdit.setText(typeOfMatch);
groundEdit.setText(ground);
homeScoreEdit.setText(homeScore);
awayScoreEdit.setText(awayScore);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String item = refEdit.getText().toString();
if(!mDatabaseHelper.checkIfRefExists(ref)) {
mDatabaseHelper.updateRef(ref);
toastMessage("Ref Updated");
}
else
{
toastMessage("No ref with that email");
}
}
});
}
/**
* customizable toast
* #param message
*/
private void toastMessage(String message){
Toast.makeText(this,message, Toast.LENGTH_SHORT).show();
}
}
I tried using the getIdFromName method when creating for the first time and it works but when I try update it, it gives me "java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)"
Totally lost here so any guidance would be appreciated.
I have a main activity where you can send a log to a database, and a log activity where you can view them and delete them. Everything works expect when I try and delete a single log, the program crashes and the error is saying that it can't find the column "identity" to delete it.
Main Activity:
package com.software.roux.diabcalc;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class MainActivity extends AppCompatActivity {
SharedPreferences mPrefs;
SharedPreferences logPrefs;
SQLiteDatabase db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
boolean rb0 = settings.getBoolean("accepted", false);
if(rb0 == true){
setTitle("MyInsulin");
mPrefs=this.getSharedPreferences("settings", 0);
logPrefs=this.getSharedPreferences("logs", 0);
final EditText a1 = (EditText) findViewById(R.id.add1);
final EditText a2 = (EditText) findViewById(R.id.add2);
final double bolusdose = Double.parseDouble(mPrefs.getString("bolus", "0"));
final double correctiondose = Double.parseDouble(mPrefs.getString("correction", "0"));
final double targetlow = Double.parseDouble(mPrefs.getString("low", "0"));
final double targethigh = Double.parseDouble(mPrefs.getString("high", "0"));
final double correctto = Double.parseDouble(mPrefs.getString("corrset", "0"));
String bolusString = mPrefs.getString("bolus", "0");
String corrString = mPrefs.getString("correction", "0");
String lowString = mPrefs.getString("low", "0");
String highString = mPrefs.getString("high", "0");
String correcttonum = mPrefs.getString("corrset", "0");
EditText b1 = (EditText)findViewById(R.id.bolus);
b1.setText(bolusString);
b1.setEnabled(false);
EditText b2 = (EditText)findViewById(R.id.correction);
b2.setText(corrString);
b2.setEnabled(false);
EditText b3 = (EditText)findViewById(R.id.targetlow);
b3.setText(lowString);
b3.setEnabled(false);
EditText b4 = (EditText)findViewById(R.id.targethigh);
b4.setText(highString);
b4.setEnabled(false);
EditText b5 = (EditText)findViewById(R.id.correcttonum);
b5.setText(correcttonum);
b5.setEnabled(false);
Button b6 = (Button)findViewById(R.id.setter);
b6.setEnabled(false);
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
db = openOrCreateDatabase("logDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS zlogtable('identity VARCHAR',bslevel VARCHAR,carbs VARCHAR,result VARCHAR);");
a1.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String currentlevelst = a1.getText().toString();
String carbseatenst = a2.getText().toString();
if (currentlevelst.length() >= 1) {
if (carbseatenst.length() >= 1) {
Double currentlevel = Double.parseDouble(a1.getText().toString());
Double carbseaten = Double.parseDouble(a2.getText().toString());
double firststep = 0;
if (currentlevel > targethigh) {
firststep = ((currentlevel - correctto) / correctiondose);
} else if (currentlevel < targetlow) {
firststep = ((currentlevel - targethigh) / correctiondose);
} else {
firststep = 0;
}
double secondstep = carbseaten / bolusdose;
double firstplussecond = firststep + secondstep;
BigDecimal result = new BigDecimal(firstplussecond, MathContext.DECIMAL64);
result = result.setScale(2, RoundingMode.CEILING);
if (result.compareTo(BigDecimal.ZERO) > 0) {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("Recommended Dose: " + result + " Units");
Button b8 = (Button) findViewById(R.id.logsave);
b8.setEnabled(true);
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("No Insulin Needed");
}
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("");
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
}
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("");
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
a2.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String currentlevelst = a1.getText().toString();
String carbseatenst = a2.getText().toString();
if (currentlevelst.length() >= 1) {
if (carbseatenst.length() >= 1) {
Double currentlevel = Double.parseDouble(a1.getText().toString());
Double carbseaten = Double.parseDouble(a2.getText().toString());
double firststep = 0;
if (currentlevel > targethigh) {
firststep = ((currentlevel - correctto) / correctiondose);
} else if (currentlevel < targetlow) {
firststep = ((currentlevel - targethigh) / correctiondose);
} else {
firststep = 0;
}
double secondstep = carbseaten / bolusdose;
double firstplussecond = firststep + secondstep;
BigDecimal result = new BigDecimal(firstplussecond, MathContext.DECIMAL64);
result = result.setScale(2, RoundingMode.CEILING);
if (result.compareTo(BigDecimal.ZERO) > 0) {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("Recommended Dose: " + result + " Units");
Button b8 = (Button) findViewById(R.id.logsave);
b8.setEnabled(true);
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("No Insulin Needed");
}
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("");
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
}
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("");
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
}else{
showDialog(0);
}}
public void addclickb(View b) throws InterruptedException {
if (b.getId() == R.id.add2) {
final EditText a1 = (EditText) findViewById(R.id.add1);
final EditText a2 = (EditText) findViewById(R.id.add2);
final double bolusdose = Double.parseDouble(mPrefs.getString("bolus", "0"));
final double correctiondose = Double.parseDouble(mPrefs.getString("correction", "0"));
final double targetlow = Double.parseDouble(mPrefs.getString("low", "0"));
final double targethigh = Double.parseDouble(mPrefs.getString("high", "0"));
final double correctto = Double.parseDouble(mPrefs.getString("corrset", "0"));
a2.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String currentlevelst = a1.getText().toString();
String carbseatenst = a2.getText().toString();
if (currentlevelst.length() >= 1) {
if (carbseatenst.length() >= 1) {
Double currentlevel = Double.parseDouble(a1.getText().toString());
Double carbseaten = Double.parseDouble(a2.getText().toString());
double firststep = 0;
if (currentlevel > targethigh) {
firststep = ((currentlevel - correctto) / correctiondose);
} else if (currentlevel < targetlow) {
firststep = ((currentlevel - targethigh) / correctiondose);
} else {
firststep = 0;
}
double secondstep = carbseaten / bolusdose;
double firstplussecond = firststep + secondstep;
BigDecimal result = new BigDecimal(firstplussecond, MathContext.DECIMAL64);
result = result.setScale(2, RoundingMode.CEILING);
if (result.compareTo(BigDecimal.ZERO) > 0) {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("Recommended Dose: " + result + " Units");
Button b8 = (Button) findViewById(R.id.logsave);
b8.setEnabled(true);
} else {
TextView t = (TextView) findViewById(R.id.answerobj);
t.setText("No Insulin Needed");
}
}
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
}
public void noweditable(View a) {
if (a.getId() == R.id.editbutton) {
EditText b1 = (EditText)findViewById(R.id.bolus);
EditText b2 = (EditText)findViewById(R.id.correction);
EditText b3 = (EditText)findViewById(R.id.targetlow);
EditText b4 = (EditText)findViewById(R.id.targethigh);
EditText b5 = (EditText)findViewById(R.id.correcttonum);
Button b6 = (Button)findViewById(R.id.setter);
Button b7 = (Button)findViewById(R.id.editbutton);
b1.setEnabled(true);
b2.setEnabled(true);
b3.setEnabled(true);
b4.setEnabled(true);
b5.setEnabled(true);
b6.setEnabled(true);
b7.setEnabled(false);
}
}
public void setclick(View b) {
if (b.getId() == R.id.setter) {
EditText b1 = (EditText)findViewById(R.id.bolus);
if (b1.length() > 0) {
String bolussave = "" + b1.getText().toString();
SharedPreferences.Editor mEditor1 = mPrefs.edit();
mEditor1.putString("bolus", bolussave).commit();
}
EditText b2 = (EditText)findViewById(R.id.correction);
if (b2.length() > 0) {
String corrsave = "" + b2.getText().toString();
SharedPreferences.Editor mEditor2 = mPrefs.edit();
mEditor2.putString("correction", corrsave).commit();
}
EditText b3 = (EditText)findViewById(R.id.targetlow);
if (b3.length() > 0) {
String lowsave = "" + b3.getText().toString();
SharedPreferences.Editor mEditor3 = mPrefs.edit();
mEditor3.putString("low", lowsave).commit();
}
EditText b4 = (EditText)findViewById(R.id.targethigh);
if (b4.length() > 0) {
String highsave = "" + b4.getText().toString();
SharedPreferences.Editor mEditor4 = mPrefs.edit();
mEditor4.putString("high", highsave).commit();
}
EditText b5 = (EditText)findViewById(R.id.correcttonum);
if (b4.length() > 0) {
String corrsetsave = "" + b5.getText().toString();
SharedPreferences.Editor mEditor5 = mPrefs.edit();
mEditor5.putString("corrset", corrsetsave).commit();
}
b1.setEnabled(false);
b2.setEnabled(false);
b3.setEnabled(false);
b4.setEnabled(false);
b5.setEnabled(false);
Button b6 = (Button)findViewById(R.id.setter);
Button b7 = (Button)findViewById(R.id.editbutton);
b6.setEnabled(false);
b7.setEnabled(true);
}
}
public void logview(View b){
if(b.getId() == R.id.logview)
{
Intent myIntent = new Intent(MainActivity.this, Settings.class);
MainActivity.this.startActivity(myIntent);
}
}
public void logsave(View b){
if(b.getId() == R.id.logsave)
{
EditText l1 = (EditText)findViewById(R.id.add1);
EditText l2 = (EditText)findViewById(R.id.add2);
TextView l3 = (TextView)findViewById(R.id.answerobj);
SharedPreferences.Editor mEditor6 = mPrefs.edit();
int incrementer = mPrefs.getInt("increment",0);
incrementer++;
mEditor6.putInt("increment", incrementer).commit();
db=openOrCreateDatabase("logDB", Context.MODE_PRIVATE, null);
db.execSQL("INSERT INTO zlogtable VALUES('"+incrementer+"','"+l2.getText()+"','"+
l1.getText()+"','"+l3.getText()+"');");
Button b8 = (Button)findViewById(R.id.logsave);
b8.setEnabled(false);
b8.setText("Saved To Log");
}
}
protected Dialog onCreateDialog(int id){
// show disclaimer....
// for example, you can show a dialog box...
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Legal Notice: The content provided through this app is for informational purposes only and does not constitute medical advice. Reliance on any information provided by this application is solely at your own risk.")
.setCancelable(false)
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// and, if the user accept, you can execute something like this:
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("accepted", true);
// Commit the edits!
editor.commit();
}
})
.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//nm.cancel(R.notification.running); // cancel the NotificationManager (icon)
System.exit(0);
}
});
AlertDialog alert = builder.create();
return alert;
}
}
Log Activity:
package com.software.roux.diabcalc;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class Settings extends AppCompatActivity {
SQLiteDatabase db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setTitle("My Logs");
db=openOrCreateDatabase("logDB", Context.MODE_PRIVATE, null);
Cursor c=db.rawQuery("SELECT * FROM zlogtable", null);
if(c.getCount()==0)
{
System.out.print("Error");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
final TextView logfield = new TextView(this);
final LinearLayout layout = (LinearLayout) findViewById(R.id.loghold);
final LinearLayout layout1 = new LinearLayout(this);
final int identifier = c.getInt(0);
logfield.append("Blood Sugar Level: "+c.getString(2)+"\n");
logfield.append("Carbs Eaten: "+c.getString(1)+"\n");
logfield.append(""+c.getString(3)+"\n");
final Button deleter = new Button(this);
deleter.setText("Delete");
deleter.setTextSize(12);
layout1.addView(logfield);
layout1.addView(deleter);
layout.addView(layout1);
deleter.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
layout1.removeView(deleter);
layout1.removeView(logfield);
db=openOrCreateDatabase("logDB", Context.MODE_PRIVATE, null);
db.execSQL("DELETE FROM zlogtable WHERE identity = "+identifier+" ");
}
});
}
TextView log1 = (TextView) findViewById(R.id.log1);
log1.setText(buffer.toString());
}
public void switchclick(View a) {
if (a.getId() == R.id.backbutton) {
Intent myIntent = new Intent(Settings.this, MainActivity.class);
Settings.this.startActivity(myIntent);
}
}
}
Looks like there is no column named 'identity' in your database. Can you check the column name for your db table.
Rotwang commented and found an error with this statement, I removed the string markers and it worked perfectly:
This is wrong: "CREATE TABLE IF NOT EXISTS zlogtable('identity VARCHAR'. Remove the ' string markers.
I am developing a android application where user can search his details by filling any of the column in multiple field form, no need to fill all the field, just has to enter any one column. But the Problem is instead of matching the entered field column it is displaying whole database.i tried filling 1 field , 2 field whatever i fill or even just click submit without entering anything it return whole database! where am i wrong?
Search.java
public class Search extends Activity {
SqlHandler sqlHandler;
EditText txtname, txt_relative_type, txt_father, txt_id, txt_part, txt_sl,
txt_age, txt_house, txt_poling, txt_section, txt_ac_name,
txt_ac_no;
ImageButton reset_btn, submit_btn;
RadioButton RdioBtn_male,RdioBtn_female;
ListView lvCustomList;
String intentname,intentacno,intentpartno,intentpoll,intentsl,intenthouse,intentAc_name,intentRelative,intentfather,intentage,intentsection;
String name1,acno,part,poll,sl,house,Ac_name,Relative,father,age,id,section,intentid;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
txtname = (EditText) findViewById(R.id.editText);
txt_relative_type = (EditText) findViewById(R.id.editText3);
txt_father = (EditText) findViewById(R.id.editText1);
txt_id = (EditText) findViewById(R.id.editText4);
txt_part = (EditText) findViewById(R.id.editText5);
txt_sl = (EditText) findViewById(R.id.editText6);
txt_age = (EditText) findViewById(R.id.editText7);
txt_house = (EditText) findViewById(R.id.editText8);
txt_poling = (EditText) findViewById(R.id.editText9);
txt_section = (EditText) findViewById(R.id.editText10);
txt_ac_name = (EditText) findViewById(R.id.editText11);
txt_ac_no = (EditText) findViewById(R.id.editText12);
reset_btn = (ImageButton) findViewById(R.id.imageButton1);
submit_btn = (ImageButton) findViewById(R.id.imageButton2);
submit_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
name1 = txtname.getText().toString();
acno = txt_ac_no.getText().toString();
part = txt_part.getText().toString();
poll = txt_poling.getText().toString();
sl = txt_sl.getText().toString();
house = txt_house.getText().toString();
Ac_name = txt_ac_name.getText().toString();
Relative= txt_relative_type.getText().toString();
father = txt_father.getText().toString();
age = txt_age.getText().toString();
id = txt_id.getText().toString();
section = txt_section.getText().toString();
Intent i = new Intent (Search.this,Listdisplay.class);
i.putExtra(intentname, name1);
i.putExtra(intentacno, acno);
i.putExtra(intentpartno, part);
i.putExtra(intentpoll, poll);
i.putExtra(intentsl, sl);
i.putExtra(intentAc_name, Ac_name);
i.putExtra(intentRelative, Relative);
i.putExtra(intentfather, father );
i.putExtra(intentage, age);
i.putExtra(intentid, id);
i.putExtra(intentsection, section);
i.putExtra(intenthouse, house);
startActivity(i);
}
});
reset_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
txtname.setText("");
txt_relative_type.setText("");
txt_father.setText("");
txt_id.setText("");
txt_part.setText("");
txt_sl.setText("");
txt_age.setText("");
txt_house.setText("");
txt_poling.setText("");
txt_section.setText("");
txt_ac_name.setText("");
txt_ac_no.setText("");
}
});
}}
Listdisplay.java
public class Listdisplay extends Activity {
ListView lvCustomList;
String intentname,intentacno,intentpartno,intentpoll,intentsl,intentAc_name,intentRelative,intentfather,intentage,intentid,intentsection,intenthouse;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchlayout);
Intent myIntent = getIntent();
String name_search = myIntent.getStringExtra(intentname);
String acno_search = myIntent.getStringExtra(intentacno);
String part_search = myIntent.getStringExtra(intentpartno);
String address_search = myIntent.getStringExtra(intentpoll);
String sl_search = myIntent.getStringExtra(intentsl);
String area_search = myIntent.getStringExtra(intentAc_name);
String guardian_search = myIntent.getStringExtra(intentRelative);
String father_search = myIntent.getStringExtra(intentfather);
String age_search1 = myIntent.getStringExtra(intentage);
String idcard_search = myIntent.getStringExtra(intentid);
String section_search = myIntent.getStringExtra(intentsection);
String house_search = myIntent.getStringExtra(intenthouse);
lvCustomList = (ListView) findViewById(R.id.listView1);
showList(name_search,acno_search,part_search,address_search,sl_search,area_search,guardian_search,father_search,age_search1,idcard_search,section_search,house_search);
}
private void showList(String name_search,String acno_search,String part_search, String address_search,String sl_search,String area_search,String guardian_search,String father_search,String age_search1,String idcard_search,String section_search,String house_search ) {
SqlHandler sql = new SqlHandler(this);
ArrayList<contactlistitems> contactlist = new ArrayList<contactlistitems>();
contactlist.clear();
String query="SELECT * FROM VoterSearch WHERE name LIKE (case when '"+name_search+"'!='' then '%"+name_search+"%' else name end) and PollAddress LIKE (case when '"+address_search+"'!='' then '%"+address_search+"%' else PollAddress end) and Relation LIKE (case when '"+guardian_search+"'!='' then '%"+guardian_search+"%' else Relation end) and FatherName LIKE (case when '"+father_search+"'!='' then '%"+father_search+"%' else FatherName end) and AcName LIKE (case when '"+area_search+"'!='' then '%"+area_search+"%' else AcName end)"
+" and Section LIKE (case when '"+section_search+"'!='' then '%"+section_search+"%' else Section end)"+" and IdCard LIKE (case when '"+idcard_search+"'!='' then '%"+idcard_search+"%' else IdCard end)"+" and SlNo = (case when '"+sl_search+"'!='' then '"+sl_search+"' else SlNo end) and AcNo = (case when '"+acno_search+"'!='' then '"+acno_search+"' else AcNo end) and PartNo = (case when '"+part_search+"'!='' then '"+part_search+"' else PartNo end)"
+" and HouseNo LIKE (case when '"+house_search+"'!='' then '%"+name_search+"%' else HouseNo end)"+" and Age BETWEEN (case when '"+age_search1+"'!='' then '"+age_search1+"' else Age end)"+" AND (case when '"+age_search1+"'!='' then '"+age_search1+"' else Age end)";
Cursor c1 = sql.selectQuery(query);
Log.i("Error","error");
if(c1 != null && c1.getCount() != 0)
{
Log.i("Error","error");
if(c1.moveToFirst()) {
do {
contactlistitems contactlistitems = new contactlistitems();
contactlistitems.setname(c1.getString(c1.getColumnIndex("name")));
contactlistitems.setrelative_type(c1.getString(c1.getColumnIndex("Relation")));
contactlistitems.setfather(c1.getString(c1.getColumnIndex("FatherName")));
contactlistitems.setid(c1.getString(c1.getColumnIndex("IdCard")));
contactlistitems.sethouse(c1.getString(c1.getColumnIndex("HouseNo")));
contactlistitems.setsl(c1.getString(c1.getColumnIndex("SlNo")));
contactlistitems.setage(c1.getString(c1.getColumnIndex("Age")));
contactlistitems.setpoling(c1.getString(c1.getColumnIndex("PollAddress")));
contactlistitems.setsection(c1.getString(c1.getColumnIndex("Section")));
contactlistitems.setac_name(c1.getString(c1.getColumnIndex("AcName")));
contactlistitems.setac_no(c1.getString(c1.getColumnIndex("AcNo")));
contactlistitems.setpart(c1.getString(c1.getColumnIndex("PartNo")));
contactlistitems.setSex(c1.getString(c1.getColumnIndex("Sex")));
contactlist.add(contactlistitems);
} while (c1.moveToNext());
}
}
c1.close();
ContactListAdapter contactListAdapter = new ContactListAdapter(Listdisplay.this, contactlist);
lvCustomList.setAdapter(contactListAdapter);
}
}
ContactListAdapter.java
public class ContactListAdapter extends BaseAdapter {
Context context;
ArrayList<contactlistitems> contactlist;
LayoutInflater mInflater;
public ContactListAdapter(Context context, ArrayList<contactlistitems> list) {
mInflater = LayoutInflater.from(context);
this.context = context;
contactlist = list;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return contactlist.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return contactlist.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.textView1);
holder.house = (TextView) convertView.findViewById(R.id.textView2);
holder.father = (TextView) convertView.findViewById(R.id.textView3);
holder.sex = (TextView) convertView.findViewById(R.id.textView4);
holder.part = (TextView) convertView.findViewById(R.id.textView5);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(contactlist.get(position).getname());
holder.house.setText(contactlist.get(position).gethouse());
holder.father.setText(contactlist.get(position).getfather());
holder.sex.setText(contactlist.get(position).getSex());
holder.part.setText(contactlist.get(position).getpart());
return convertView;
}
static class ViewHolder
{
TextView name,house,father,sex,part;
}
}
I believe that the query is perfectly right! dont know from where its going wrong, is it passing values from class search to listadisplay through intent causing problem am not sure. Kindly help with this
When i tried with the live database the query was working fine. problem was whole data base was returned instead of match, hence the query may be returning null, now have to look for code. When i tested the value which i got through getIntent() it was not receiving value, hence the problem was with intent, value was not sent. error was just to enclose double quote in intent and getintent
at Search.java double quote parameter
i.putExtra("intentname", name1);
at ListDisplay.java
String name_search = myIntent.getStringExtra("intentname");
And it worked