My Android app fails to display the shared preferences that I set in a different class.
Am I missing something in my code? I save them fine but they don't display in my main Activity. All I see is the default text when I run the app. I have tried all I can to no avail. I can't figure out where the problem is. Below are my code files:
1. MnsEditor.java
public class MnsEditor extends Activity {
private MsItem mnses;
private Button saveBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mns_editor);
Intent intent = this.getIntent();
mnses = new MsItem();
mnses.setStartKey(intent.getStringExtra("startKey"));
mnses.setStartDate(intent.getStringExtra("StartDate"));
mnses.setShiftKey(intent.getStringExtra("ShiftKey"));
mnses.setShift(intent.getStringExtra("Shift"));
mnses.setBKey(intent.getStringExtra("BKey"));
mnses.setB(intent.getStringExtra("B"));
mnses.setGKey(intent.getStringExtra("GKey"));
mnses.setG(intent.getStringExtra("G"));
mnses.setNxtKey(intent.getStringExtra("NxtKey"));
mnses.setNxt(intent.getStringExtra("Nxt"));
EditText ms = (EditText) findViewById(R.id.sdate);
ms.setText(mnses.getStartDate());
EditText sh = (EditText) findViewById(R.id.sDay);
sh.setText(mnses.getShift());
EditText bb = (EditText) findViewById(R.id.bB);
bb.setText(mnses.getB());
EditText bg = (EditText) findViewById(R.id.bG);
bg.setText(mnses.getG());
EditText nm = (EditText) findViewById(R.id.Nxt);
nm.setText(mnses.getNxt());
saveBtn = (Button) findViewById(R.id.savePrefs);
saveBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
saveAndFinish();
}
});
}
private void saveAndFinish() {
EditText mst = (EditText) findViewById(R.id.stDay);
String mnsesStart = mst.getText().toString();
EditText shi = (EditText) findViewById(R.id.ShiftDay);
String shift = shi.getText().toString();
EditText bb = (EditText) findViewById(R.id.bbB);
String bbb = b.getText().toString();
EditText gg = (EditText) findViewById(R.id.ggG);
String ggg = gg.getText().toString();
EditText nxt = (EditText) findViewById(R.id.Nxt);
String next = nxt.getText().toString();
Intent intent = new Intent();
intent.putExtra("startdatekey", mnses.getStartDate());
intent.putExtra("StartDate", mnsesStart);
intent.putExtra("ShiftKey", mnses.getShift());
intent.putExtra("Shift", shift);
intent.putExtra("BKey", mnses.getB());
intent.putExtra("B", bbb);
intent.putExtra("GKey", mnses.getG());
intent.putExtra("G", ggg);
intent.putExtra("NxtKey", mnses.getNxt());
intent.putExtra("Nxt", next);
setResult(RESULT_OK, intent);
finish();
}
}
2. MsDataSource.java
public class MsDataSource {
MsItem mnses;
private static final String MNS_PREFS = "mnsKEY";
public SharedPreferences mnsPrefs;
public static final String StartDate = "startKey";
public static final String Shift = "shiftKey";
public static final String B = "bKey";
public static final String G = "gKey";
public static final String Nxt = "nxtKey";
public MsDataSource(Context context) {
mnsPrefs = context.getSharedPreferences(MNS_PREFS, Context.MODE_PRIVATE);
}
public String getTheStartDate() {
String mnsstart = mensPrefs.getString(StartDate, "Not seen");
return mnsstart;
}
public String getTheShift() {
String shiftda = mensPrefs.getString(Ovulation, "no data");
return shiftda;
}
public String getTheBoy() {
String Bda = mensPrefs.getString(B, "not accessible");
return Bda;
}
public String getTheGirl() {
String Gda = mensPrefs.getString(G, "does not exist");
return Gda;
}
public String getTheNextMenses() {
String nxtmns = mensPrefs.getString(Nxt, "maybe later");
return nxtmns;
}
public boolean update(mnsesItem mns) {
SharedPreferences.Editor editor = mnsPrefs.edit();
editor.putString(mns.getStartKey(), mns.getStartDate());
editor.putString(mns.getShiftKey(), mns.getShift());
editor.putString(mns.getBKey(), mns.getB());
editor.putString(mns.getGKey(), mns.getG());
editor.putString(mns.getNxtKey(), mns.getNxt());
editor.commit();
return true;
}
}
3. Mst.java
public class Mst extends Activity {
private TextView startdate;
private TextView shiftday;
private TextView bday;
private TextView gday;
private TextView nextday;
public static final String StartDate = "startKey";
public static final String Shift = "shiftKey";
public static final String B = "bKey";
public static final String G = "gKey";
public static final String Nxt = "nxtKey";
private static final int EDITOR_ACTIVITY_REQUEST = 1001;
private MsDataSource datasource;
MsItem mnses;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mns_layout);
startdate = (TextView) findViewById(R.id.mnsstartd);
shiftday = (TextView) findViewById(R.id.shd);
bday = (TextView) findViewById(R.id.bbd);
gday = (TextView) findViewById(R.id.bgd);
nextday = (TextView) findViewById(R.id.nxtmnsd);
datasource = new MsDataSource(this);
refreshDisplay();
}
private void refreshDisplay() {
mnses = datasource.findAll();
startdate.setText(datasource.mnsPrefs.getString(StartDate, "not retrieved"));
shiftday.setText(datasource.mnsPrefs.getString(Shift, "unavailable"));
bday.setText(datasource.mnsPrefs.getString(B, "not seen"));
gday.setText(datasource.mnsPrefs.getString(G, "not found"));
nextday.setText(datasource.mnsPrefs.getString(Nxt, "no data"));
}
private void createMns() {
MsItem mns = MsItem.getNew();
Intent intent = new Intent(this, MnsEditor.class);
intent.putExtra("startKey", mns.getStartKey());
intent.putExtra("StartDate", mns.getStartDate());
intent.putExtra("shiftKey", mns.getShiftKey());
intent.putExtra("Shift", mns.getShift());
intent.putExtra("bKey", mns.getBKey());
intent.putExtra("B", mns.getB());
intent.putExtra("gKey", mns.getGKey());
intent.putExtra("G", mns.getG());
intent.putExtra("nxtKey", mns.getNxtKey());
intent.putExtra("Nxt", mns.getNxt());
startActivityForResult(intent, EDITOR_ACTIVITY_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == EDITOR_ACTIVITY_REQUEST && resultCode == RESULT_OK) {
MsItem mns = new MsItem();
mns.setStartKey(data.getStringExtra("startKey"));
mns.setStartDate(data.getStringExtra("StartDate"));
mns.setShiftKey(data.getStringExtra("shiftKey"));
mns.setShift(data.getStringExtra("Shift"));
mns.setBKey(data.getStringExtra("bKey"));
mns.setB(data.getStringExtra("B"));
mns.setGKey(data.getStringExtra("gKey"));
mns.setG(data.getStringExtra("G"));
mns.setNextmnsesKey(data.getStringExtra("nxtKey"));
mns.setNxt(data.getStringExtra("Nxt"));
datasource.update(mns);
refreshDisplay();
}
}
}
4. MsItem.java
#SuppressLint("SimpleDateFormat")
public class MsItem {
private String startKey;
private String StartDate;
private String shiftKey;
private String Shift;
private String bKey;
private String B;
private String gKey;
private String G;
private String nxtKey;
private String Nxt;
public String getStartKey() {
return startKey;
}
public void setStartKey(String startKey) {
this.startKey = startKey;
}
public String getStartDate() {
return StartDate;
}
public void setStartDate(String startDate) {
StartDate = startDate;
}
public String getShiftKey() {
return shiftKey;
}
public void setShiftKey(String shiftKey) {
this.shiftKey = shiftKey;
}
public String getShift() {
return Shift;
}
public void setShift(String shift) {
Shift = shift;
}
public String getbKey() {
return bKey;
}
public void setbKey(String bKey) {
this.bKey = bKey;
}
public String getB() {
return B;
}
public void setB(String b) {
B = b;
}
public String getgKey() {
return gKey;
}
public void setgKey(String gKey) {
this.gKey = gKey;
}
public String getG() {
return G;
}
public void setG(String g) {
G = g;
}
public String getNxtKey() {
return nxtKey;
}
public void setNxtKey(String nxtKey) {
this.nxtKey = nxtKey;
}
public String getNxt() {
return Nxt;
}
public void setNxt(String nxt) {
Nxt = nxt;
}
public static MsItem getNew(){
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
String pattern = "yyyy-MM-dd HH:mm:ss Z";
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
String startdatekey = formatter.format(new Date());
String skey = formatter.format(new Date());
String bkey = formatter.format(new Date());
String gkey = formatter.format(new Date());
String nkey = formatter.format(new Date());
MsItem mnses = new MsItem();
mnses.setStartKey(startdatekey);
mnses.setStartDate("");
mnses.setShiftKey(skey);
mnses.setShift("");
mnses.setbKey(bkey);
mnses.setB("");
mnses.setgKey(gkey);
mnses.setG("");
mnses.setNxtKey(nkey);
mnses.setNxt("");
return mnses;
}
}
Try this:
public String getStartDate(){
mnsPrefs = context.getSharedPreferences(StartDate, Context.MODE_PRIVATE);
String mnsstart = mnsPrefs.getString(StartDate, "");
return mnsstart;
}
public String getShift(){
mnsPrefs = context.getSharedPreferences(shift, Context.MODE_PRIVATE);
String shiftda = mnsPrefs.getString(Shift, "");
return shiftda;
}
its more readable
Use MODE_APPEND instead MODE_PRIVATE.
MODE_APPEND(File creation mode: for use with openFileOutput, if the file already exists then write data to the end of the existing file instead of erasing it).
SharedPreferences editor = context.getSharedPreferences(
"used_name", Context.MODE_APPEND);
editor.putString("username", value);
editor.commit();
One issue I can see is, that You are trying to get the sharedPreferences, but You are initializing the same object a few times inside Your MsDataSource.java class:
mnsPrefs = context.getSharedPreferences(StartDate, Context.MODE_PRIVATE);
mnsPrefs = context.getSharedPreferences(shift, Context.MODE_PRIVATE);
mnsPrefs = context.getSharedPreferences(B, Context.MODE_PRIVATE);
mnsPrefs = context.getSharedPreferences(G, Context.MODE_PRIVATE);
mnsPrefs = context.getSharedPreferences(Nxt, Context.MODE_PRIVATE);
So this will not work. For different sharedPref objects, You need to initialize them unique for example:
public SharedPreferences mnsPrefs1;
public SharedPreferences mnsPrefs2;
public SharedPreferences mnsPrefs3;
public SharedPreferences mnsPrefs4;
public SharedPreferences mnsPrefs5;
mnsPrefs1 = context.getSharedPreferences(StartDate, Context.MODE_PRIVATE);
mnsPrefs2 = context.getSharedPreferences(shift, Context.MODE_PRIVATE);
mnsPrefs3 = context.getSharedPreferences(B, Context.MODE_PRIVATE);
mnsPrefs4 = context.getSharedPreferences(G, Context.MODE_PRIVATE);
mnsPrefs5 = context.getSharedPreferences(Nxt, Context.MODE_PRIVATE);
but there must be more. I need to see Your code from MsItem.java class, I think, here You are saving the SharedPrefs, right?
EDIT
You don´t need to initialize so many SharedPreference objects, it´s enough to make only one and give it different keys for every value. For example:
private final String sharedPrefKey = "MY_KEY";
public MsDataSource(Context context) {
mnsPrefs = context.getSharedPreferences(sharedPrefKey, Context.MODE_PRIVATE);
}
and then update() method in MsDataSource.java should work. But by the way, I think Your initialization of Your MsItem in Your Mst.java class at onActivityResult is made in the wrong way, isn´t it? You wrote
MsItem mns = new MsItem();
But musn´t it be
MsItem mns = MsItem.getNew();
? Because with only new MsItem(), all the Strings and stuff are not initialized inside MsItem.
Related
I'm sorry if you find my question confusing, I do hope someone will understand and help me fix the error. I am trying to make my quiz application using Java as my language in Android Studio.
All methods of my questionpage.java are running properly, it displays the index 0 question and options and executes its right wrong event, but my method changeNextQuestion does not do its work.
It always goes back to my previous activity whenever I click the next button after answering the first question.
The changeNextQuestion method's expected function is to update and display the questions on a textView and options on an app compat button and redo the other functions like its right wrong event. I'm guessing that I need a for loop and I already tried it but it didn't work. Thank you in advance, I am truly grateful!
This is my questionpage,java this is where most of my functions are
``
package com.example.quizision;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class questionpage extends AppCompatActivity {
private TextView question;
private TextView questions;
private AppCompatButton option1, option2, option3, option4;
private AppCompatButton nextbtn;
private Timer quizTimer;
private List<QuestionList> questionsList;
private int currentQuestionPosition = 0;
private int totalTimeinMins = 5;
private int seconds = 0;
private String selectedOptionByUser = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questionpage);
final ImageView back = findViewById(R.id.bckbtn);
final TextView selectedTopicName = findViewById(R.id.topic);
final TextView timer = findViewById(R.id.timer);
final String getSelectedTopicName = getIntent().getStringExtra("selectedTopicName");
selectedTopicName.setText(getSelectedTopicName);
question = findViewById(R.id.question);
questions = findViewById(R.id.questions);
option1 = findViewById(R.id.option1);
option2 = findViewById(R.id.option2);
option3 = findViewById(R.id.option3);
option4 = findViewById(R.id.option4);
nextbtn = findViewById(R.id.nextbtn);
questionsList = QuestionBank.getQuestions(getSelectedTopicName);
startTimer(timer);
questions.setText((currentQuestionPosition + 1) + "/" + questionsList.size());
question.setText(questionsList.get(0).getQuestion());
option1.setText(questionsList.get(0).getOption1());
option2.setText(questionsList.get(0).getOption2());
option3.setText(questionsList.get(0).getOption3());
option4.setText(questionsList.get(0).getOption4());
option1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (selectedOptionByUser.isEmpty()) {
selectedOptionByUser = option1.getText().toString();
option1.setBackgroundResource(R.drawable.redb);
option1.setTextColor(Color.WHITE);
revealAnswer();
questionsList.get(currentQuestionPosition).setUserSelectedAnswer(selectedOptionByUser);
}
}
});
option2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (selectedOptionByUser.isEmpty()) {
selectedOptionByUser = option2.getText().toString();
option2.setBackgroundResource(R.drawable.redb);
option2.setTextColor(Color.WHITE);
revealAnswer();
questionsList.get(currentQuestionPosition).setUserSelectedAnswer(selectedOptionByUser);
}
}
});
option3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (selectedOptionByUser.isEmpty()) {
selectedOptionByUser = option3.getText().toString();
option3.setBackgroundResource(R.drawable.redb);
option3.setTextColor(Color.WHITE);
revealAnswer();
questionsList.get(currentQuestionPosition).setUserSelectedAnswer(selectedOptionByUser);
}
}
});
option4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (selectedOptionByUser.isEmpty()) {
selectedOptionByUser = option4.getText().toString();
option4.setBackgroundResource(R.drawable.redb);
option4.setTextColor(Color.WHITE);
revealAnswer();
questionsList.get(currentQuestionPosition).setUserSelectedAnswer(selectedOptionByUser);
}
}
});
nextbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (selectedOptionByUser.isEmpty()) {
Toast.makeText(questionpage.this, "Please choose an answer", Toast.LENGTH_SHORT).show();
}
else {
changeNextQuestion();
}
}
});
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
quizTimer.purge();
quizTimer.cancel();
startActivity(new Intent(questionpage.this, categorypage.class));
finish();
}
});
}
#SuppressLint("SetTextI18n")
private void changeNextQuestion() {
currentQuestionPosition ++;
if ((currentQuestionPosition + 1) == questionsList.size()) {
nextbtn.setText("Submit Quiz");
}
if (currentQuestionPosition <= questionsList.size()) {
selectedOptionByUser = "";
option1.setBackgroundResource(R.drawable.button1);
option1.setTextColor(Color.parseColor("FF000000"));
option2.setBackgroundResource(R.drawable.button1);
option2.setTextColor(Color.parseColor("FF000000"));
option3.setBackgroundResource(R.drawable.button1);
option3.setTextColor(Color.parseColor("FF000000"));
option4.setBackgroundResource(R.drawable.button1);
option4.setTextColor(Color.parseColor("FF000000"));
questions.setText((currentQuestionPosition + 1) + "/" + questionsList.size());
question.setText(questionsList.get(currentQuestionPosition).getQuestion());
option1.setText(questionsList.get(currentQuestionPosition).getOption1());
option2.setText(questionsList.get(currentQuestionPosition).getOption2());
option3.setText(questionsList.get(currentQuestionPosition).getOption3());
option4.setText(questionsList.get(currentQuestionPosition).getOption4());
}
else {
Intent intent = new Intent(questionpage.this, quizresult.class);
intent.putExtra("correct", getCorrectAnswers());
intent.putExtra("incorrect", getIncorrectAnswers());
startActivity(intent);
finish();
}
}
private void startTimer (TextView timerTextView){
quizTimer = new Timer();
quizTimer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
if (seconds == 0) {
totalTimeinMins--;
seconds = 59;
} else if (seconds == 0 && totalTimeinMins == 0) {
quizTimer.purge();
quizTimer.cancel();
Toast.makeText(questionpage.this, "Time Over", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(questionpage.this, quizresult.class);
intent.putExtra("correct", getCorrectAnswers());
intent.putExtra("incorrect", getIncorrectAnswers());
startActivity(intent);
finish();
} else {
seconds--;
}
runOnUiThread(new Runnable() {
#Override
public void run() {
String finalMinutes = String.valueOf(totalTimeinMins);
String finalSeconds = String.valueOf(seconds);
if (finalMinutes.length() == 1) {
finalMinutes = "0" + finalMinutes;
}
if (finalSeconds.length() == 1) {
finalSeconds = "0" + finalSeconds;
}
timerTextView.setText(finalMinutes + ":" + finalSeconds);
}
});
}
}, 1000, 1000);
}
private int getCorrectAnswers () {
int correctAnswers = 0;
for (int i = 0; i < questionsList.size(); i++) {
final String getUserSelectedAnswer = questionsList.get(i).getUserSelectedAnswer();
final String getAnswer = questionsList.get(i).getAnswer();
if (getUserSelectedAnswer.equals(getAnswer)) {
correctAnswers++;
}
}
return correctAnswers;
}
private int getIncorrectAnswers () {
int correctAnswers = 0;
for (int i = 0; i < questionsList.size(); i++) {
final String getUserSelectedAnswer = questionsList.get(i).getUserSelectedAnswer();
final String getAnswer = questionsList.get(i).getAnswer();
if (!getUserSelectedAnswer.equals(getAnswer)) {
correctAnswers++;
}
}
return correctAnswers;
}
#Override
public void onBackPressed () {
quizTimer.purge();
quizTimer.cancel();
startActivity(new Intent(questionpage.this, categorypage.class));
finish();
}
private void revealAnswer () {
final String getAnswer = questionsList.get(currentQuestionPosition).getAnswer();
if (option1.getText().toString().equals(getAnswer)) {
option1.setBackgroundResource(R.drawable.greenb);
option1.setTextColor(Color.WHITE);
} else if (option2.getText().toString().equals(getAnswer)) {
option2.setBackgroundResource(R.drawable.greenb);
option2.setTextColor(Color.WHITE);
} else if (option3.getText().toString().equals(getAnswer)) {
option3.setBackgroundResource(R.drawable.greenb);
option3.setTextColor(Color.WHITE);
} else if (option4.getText().toString().equals(getAnswer)) {
option4.setBackgroundResource(R.drawable.greenb);
option4.setTextColor(Color.WHITE);
}
}
}
``
This is my QuestionList.java
package com.example.quizision;
public class QuestionList {
private String question, option1, option2, option3, option4, answer;
private String userSelectedAnswer;
public QuestionList(String question, String option1, String option2, String option3, String option4, String answer, String userSelectedAnswer) {
this.question = question;
this.option1 = option1;
this.option2 = option2;
this.option3 = option3;
this.option4 = option4;
this.answer = answer;
this.userSelectedAnswer = userSelectedAnswer;
}
public String getQuestion() {
return question;
}
public String getOption1() {
return option1;
}
public String getOption2() {
return option2;
}
public String getOption3() {
return option3;
}
public String getOption4() {
return option4;
}
public String getAnswer() {
return answer;
}
public String getUserSelectedAnswer() {
return userSelectedAnswer;
}
public void setUserSelectedAnswer(String userSelectedAnswer) {
this.userSelectedAnswer = userSelectedAnswer;
}
}
**This is my QuestionBank.java which contains my array.**
package com.example.quizision;
import java.util.ArrayList;
import java.util.List;
public class QuestionBank {
private static List<QuestionList> shsquestions () {
final List<QuestionList> questionLists = new ArrayList<>();
final QuestionList question1 = new QuestionList("What is the smallest unit of language that carries information about meaning or function?", "morpheme","expression", "dialect","semantics", "morpheme", "");
final QuestionList question2 = new QuestionList("Which of the following is not considered a social science?", "sociology","economics", "philosophy","geography", "philosophy", "");
final QuestionList question3 = new QuestionList("The basic goal of computer process is to convert data into?", "document","information", "malware","spreadsheet", "information", "");
final QuestionList question4 = new QuestionList("What kind of memory is both static and non-volatile?", "RAM","ROM", "SSD","HDD", "ROM", "");
final QuestionList question5 = new QuestionList("Scientific Name of Computer?", "Siling haba","Silicon implant", "Sillico sapiens","Sillica sapiens", "Sillico sapiens", "");
final QuestionList question6 = new QuestionList("What converts an entire program into machine language?", "compiler","file explorer", "translator","processor", "compiler", "");
final QuestionList question7 = new QuestionList("Used to fillet fish and to remove raw meat from the bone", "boning knife","boner knife", "boring knife","ngipin mo", "boning knife", "");
final QuestionList question8 = new QuestionList("Type of Kitchen Cleaning Agents often called degreaser", "rugby","solvent", "ecstacy","tawas", "solvent", "");
final QuestionList question9 = new QuestionList("What is the financial gain made in transactions?", "salary","resource", "gain","profit", "profit", "");
final QuestionList question10 = new QuestionList("What is a legal entity owned by individual stockholders?", "corporation","capital", "investment","construction site", "corporation", "");
questionLists.add(question1);
questionLists.add(question2);
questionLists.add(question3);
questionLists.add(question4);
questionLists.add(question5);
questionLists.add(question6);
questionLists.add(question7);
questionLists.add(question8);
questionLists.add(question9);
questionLists.add(question10);
return questionLists;
}
private static List<QuestionList> collegequestions () {
final List<QuestionList> questionLists = new ArrayList<>();
final QuestionList question1 = new QuestionList("Par, masaya ka ba sa course mo?", "tanginang prof yon, samal","oo sobra", "okay lang","hindi", "hindi", "");
final QuestionList question2 = new QuestionList("Pustahan need mo mag summer class this school year haha", "gagi pano mo alam","opo, bobo kasi ako e", "opo","no dzuh", "opo, bobo kasi ako e", "");
final QuestionList question3 = new QuestionList("G ka ba sa wanayt stan?", "no, i want true love","pag hindi na makamot, pwede na rin siguro", "yan ang when","hahaha g", "yan ang when", "");
final QuestionList question4 = new QuestionList("Bat ba kasi yan yung pinili mong course, e bobo ka?", "grabe ka naman","if u aim high, early u will die", "pake mo ba","'di mo kasi alam feeling ng may anxiety", "pake mo ba", "");
final QuestionList question5 = new QuestionList("Kamusta profs?", "sarap pumatay","k lng", "hindi nagtuturo ampota","baoninato may sakey aga mambabangat", "k lng", "");
final QuestionList question6 = new QuestionList("Kamusta mga blockmates?", "puro maansit hshshs","walang chinita na short hair pota", "dami mong tanong","aolid", "dami mong tanong", "");
final QuestionList question7 = new QuestionList("Sapat ba baon mo beh?", "nangyan lahat nabuhos sa pamasahe","gago yung pagkain sa canteen, presyong ginto", "sapat po hehe","hindi tanginamo,ikaw kaya bigyan ng bente", "sapat po hehe", "");
final QuestionList question8 = new QuestionList("Sure ka ba? na may future ka diyan?", "what if umiyak ako","oo", "hindi huhu","ano, kape lang ganon", "ano, kape lang ganon", "");
final QuestionList question9 = new QuestionList("What is the financial gain made in transactions?", "salary","resource", "gain","profit", "profit", "");
final QuestionList question10 = new QuestionList("Matatapos mo ba ang course mo?", "yes, without a doubt","omsimized fr", "opo hehe, para kay mama","sinabawang medyas", "sinabawang medyas", "");
questionLists.add(question1);
questionLists.add(question2);
questionLists.add(question3);
questionLists.add(question4);
questionLists.add(question5);
questionLists.add(question6);
questionLists.add(question7);
questionLists.add(question8);
questionLists.add(question9);
questionLists.add(question10);
return questionLists;
}
public static List<QuestionList> getQuestions (String selectedTopicName){
if ("SHS category".equals(selectedTopicName)) {
return shsquestions();
}
return collegequestions();
}
}
Please I need your help .I'am trying to take the date from an activity and then put it in an array list then print it in an ListView .
The problem is the data that I should take it from "Adding Todo" is not showing in the ListView . it do take me to the List Activity but without showing the data .
This is How the app going to be "Adding todo"
And this is the ListView where the data should be in it
My code :-
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list_view);
arrayList = new ArrayList<>();
todoAdapter = new TodoAdapter(this , arrayList);
listView.setAdapter(todoAdapter);
}
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, AddTodo.class);
startActivityForResult(intent, Intent_Constants.INTENT_REQUEST_CODE);
}
protected void onActivityResult(int reqCode ,int resultCode , Intent data ){
// here Iam trying to get the data from ADDING TO DO class
if(resultCode == Intent_Constants.INTENT_REQUEST_CODE){
titleText = data.getStringExtra(Intent_Constants.INTENT_TITLE);
priorityText = data.getStringExtra(Intent_Constants.INTENT_PRIORITY);
statusText = data.getStringExtra(Intent_Constants.INTENT_STATUES);
dateText = data.getStringExtra(Intent_Constants.INTENT_DATE);
timeText = data.getStringExtra(Intent_Constants.INTENT_TIME);
todoAdapter.todo.add(new Todo (titleText , statusText ,priorityText ,dateText ,timeText));
}
}
Intent_Constants
public class Intent_Constants {
public final static int INTENT_REQUEST_CODE = 1;
public final static int INTENT_RESULT_CODE = 1 ;
public final static String INTENT_TITLE = "Title";
public final static String INTENT_PRIORITY = "Priority";
public final static String INTENT_TIME = "Time";
public final static String INTENT_DATE = "Date";
public final static String INTENT_STATUES = "Statues";
}
AddTodo class
In this class I find the id then I converted to String
public void saveButton (View view){
Intent intent = new Intent();
intent.putExtra(Intent_Constants.INTENT_TITLE , title);
intent.putExtra(Intent_Constants.INTENT_DATE , date);
intent.putExtra(Intent_Constants.INTENT_TIME , time);
intent.putExtra(Intent_Constants.INTENT_PRIORITY , priority);
intent.putExtra(Intent_Constants.INTENT_STATUES , completed);
setResult(INTENT_RESULT_CODE, intent);
finish();
}
TodoAdapter class
ArrayList<Todo> todo ;
public TodoAdapter(#NonNull Context context, ArrayList<Todo> todo) {
super(context, R.layout.todo_list,todo);
this.todo = todo;
}
public static class ViewHolder {
TextView titleText;
TextView priorityText;
TextView dateText;
TextView timeText;
CheckBox statusBox;
ImageButton edit_image;
ImageButton open_image;
ImageButton delet_image;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater inflater = LayoutInflater.from(getContext()) ;
View customeView =inflater.inflate(R.layout.todo_list,parent ,false);
holder.titleText.setText(getItem(position).getTitle());
holder.priorityText.setText(getItem(position).getPriority());
holder.dateText.setText(getItem(position).getDate());
holder.timeText.setText(getItem(position).getTime());
holder.statusBox.setChecked(false);
holder.edit_image = customeView.findViewById(R.id.edit_imageView);
holder.open_image = customeView.findViewById(R.id.open_imageButton);
holder.delet_image = customeView.findViewById(R.id.delete_imageView);
holder.edit_image.setImageResource(R.drawable.ic_edit_black_24dp);
holder.open_image.setImageResource(R.drawable.ic_refresh_black_24dp);
holder.delet_image.setImageResource(R.drawable.ic_delete_black_24dp);
return customeView;
}
Todo class
public class Todo {
private String title ;
private String status ;
private String priority ;
private String date ;
private String time ;
public Todo() {
}
public Todo(String title, String status, String priority, String date, String time) {
this.title = title;
this.status = status;
this.priority = priority;
this.date = date;
this.time = time;
}
public String getTitle() {
return title;
}
public String getStatus() {
return status;
}
public String getPriority() {
return priority;
}
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public void setTitle(String title) {
this.title = title;
}
public void setStatus(String status) {
this.status = status;
}
public void setPriority(String priority) {
this.priority = priority;
}
public void setDate(String date) {
this.date = date;
}
public void setTime(String time) {
this.time = time;
}
}
You can just set a new adapter, I know it isn't best way, but should do the work. Don't create new one, but nulify yours, and initialize it with new data.
#Noura change this
arrayList.add(new Todo(titleText , statusText ,priorityText ,dateText ,timeText));
to
todoAdapter.todo.add(new Todo(titleText , statusText ,priorityText ,dateText ,timeText));
todoAdapter.notifyDataSetChanged();
and at the constructor u need to update your code like below
ArrayList<Todo> todo ;
public TodoAdapter(#NonNull Context context, ArrayList<Todo> todo) {
this.todo = todo
super(context, R.layout.todo_list,todo);
}
I have created some editText box in my activity it's like an Update form and all I am trying to do now is to set random value to all the check box whichever is left blank while hitting the submit button. what I am getting is... getting value in only ETname edittext box and if I am clicking on submit button again my app is crashing and even if I am giving any value by myself to ETname and submitting it my app is crashing. please help.
public class User_Profile extends AppCompatActivity implements View.OnClickListener {
private Button Update;
private Context aContext;
private EditText ETname, ETsurname, ETadd, ETpin, ETmail, ETph;
ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userprofile);
ETname = (EditText)findViewById(R.id.edit_name);
ETsurname = (EditText)findViewById(R.id.edit_sur);
ETadd = (EditText)findViewById(R.id.edit_add);
ETpin = (EditText)findViewById(R.id.edit_pn);
ETmail = (EditText)findViewById(R.id.edit_mail);
ETph = (EditText)findViewById(R.id.edit_ph);
Update = (Button)findViewById(R.id.update_btn);
progressDialog = new ProgressDialog(this);
Update.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.update_btn:
proUpdate();
break;
}
}
private void proUpdate(){
if (ETname.getText().toString().trim().equals("")){
ETname.setText(SharedPrefManager.getInstance(this).getName());
}
if (ETsurname.getText().toString().trim().equals("")){
ETsurname.setText(SharedPrefManager.getInstance(this).getSurname());
}
if (ETadd.getText().toString().trim().equals("")){
ETadd.setText(SharedPrefManager.getInstance(this).getAddress());
}
if (ETpin.getText().toString().trim().equals("")){
String pin = String.valueOf(SharedPrefManager.getInstance(this).getpin());
ETpin.setText(pin);
}
if (ETmail.getText().toString().trim().equals("")){
ETmail.setText(SharedPrefManager.getInstance(this).getUserEmail());
}
if (ETph.getText().toString().equals("")){
ETph.setText(SharedPrefManager.getInstance(this).getUserPhone());
}
String reg_name = ETname.getText().toString().trim();
String reg_surname = ETsurname.getText().toString().trim();
String reg_address = ETadd.getText().toString().trim();
String reg_pin = ETpin.getText().toString().trim();
String reg_mail = ETmail.getText().toString().trim();
String reg_phone = ETph.getText().toString().trim();
String old_mail = (SharedPrefManager.getInstance(this).getUserEmail());
int reg_id = (SharedPrefManager.getInstance(this).getid());
}
}
My SharedPrefManager
public class SharedPrefManager {
private static SharedPrefManager mInstance;
private static Context mCtx;
private static final String SHARED_PREF_NAME = "mysharedpref12";
private static final String KEY_USERNAME = "username";
private static final String KEY_USER_MAIL = "usermail";
private static final String KEY_USER_ID = "userid";
private static final String KEY_PHONE = "userphone";
private static final String KEY_NAME = "usename";
private static final String KEY_PIN = "pin";
private static final String KEY_SUR = "surname";
private static final String KEY_ADD = "address";
private SharedPrefManager(Context context) {
mCtx = context;
}
public static synchronized SharedPrefManager getInstance(Context context) {
if (mInstance == null) {
mInstance = new SharedPrefManager(context);
}
return mInstance;
}
public boolean userLogin(int id, int pin, String phone, String username, String mail, String name, String surname, String address/**, String catagory*/){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(KEY_USER_ID, id);
editor.putInt(KEY_PIN, pin);
editor.putString(KEY_PHONE, phone);
editor.putString(KEY_USERNAME, username);
editor.putString(KEY_USER_MAIL, mail);
editor.putString(KEY_NAME, name);
editor.putString(KEY_SUR, surname);
editor.putString(KEY_ADD, address);
//editor.putString(KEY_CATA, catagory);
editor.apply();
return true;
}
public boolean isLoggedIn(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
if (sharedPreferences.getString(KEY_USERNAME, null) != null){
return true;
}
return false;
}
public boolean logOut(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.apply();
return true;
}
public int getid(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(KEY_USER_ID, Integer.parseInt(null));
}
public int getpin(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(KEY_PIN, Integer.parseInt(null));
}
public String getUsername(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_USERNAME, null);
}
public String getUserEmail(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_USER_MAIL, null);
}
public String getUserPhone(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_PHONE, null);
}
public String getName() {
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_NAME, null);
}
public String getSurname() {
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_SUR, null);
}
public String getAddress() {
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_ADD, null);
}
/**public String getcatagory() {
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_CATA, null);
}*/
}
Here's the code sample of what I was telling you.
private void proUpdate(){
...
else if (ETpin.getText().toString().equals("")){
string pin = String.valueOf(SharedPrefManager.getInstance(this).getpin());
ETpin.setText(pin);
}
...
}
For checking and placing text in all edittext at once:
private void proUpdate(){
if (ETname.getText().toString().trim().equals("")){
ETname.setText(SharedPrefManager.getInstance(this).getName());
}
if (ETsurname.getText().toString().trim().equals("")){
ETsurname.setText(SharedPrefManager.getInstance(this).getSurname());
}
if (ETadd.getText().toString().trim().equals("")){
ETadd.setText(SharedPrefManager.getInstance(this).getAddress());
}
if (ETph.getText().toString().equals("")){
ETph.setText(SharedPrefManager.getInstance(this).getUserPhone());
}
if (ETmail.getText().toString().trim().equals("")){
ETmail.setText(SharedPrefManager.getInstance(this).getUserEmail());
}
if (ETpin.getText().toString().equals("")){
string pin = String.valueOf(SharedPrefManager.getInstance(this).getpin());
ETpin.setText(pin);
}
updateMethodCall(); // your method call
}
This updateMethod will only be called when all the ediitexts are filled and you need not click submit button again.
Change following methods a bit like this.
public int getid(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(KEY_USER_ID, 0);
}
public int getpin(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(KEY_PIN,0);
}
I want to add a Password Validation on this, but getting problem in getting it, I want a password pattern which includes at least some of these:
number of characters
special characters
lowercase letters
uppercase letters
But I am unable to achieve this, please help.
I am using Android Studio, below is my Java class file:
public class SignUp extends MainActivity {
private EditText et_name, et_email, et_password, et_cpassword;
private String name, email, password, cpassword;
Button signupbtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up_form);
et_name = (EditText) findViewById(R.id.name);
et_email = (EditText) findViewById(R.id.Email);
et_password = (EditText) findViewById(R.id.Password);
et_cpassword = (EditText) findViewById(R.id.Confirm_Password);
signupbtn = (Button) findViewById(R.id.Signbtn);
signupbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register();
}
});
}
public void register() {
initialise();
if (!validate()) {
Toast.makeText(this, "Sign up Failed", Toast.LENGTH_SHORT).show();
} else {
onSignUpSuccess();
}
}
public void onSignUpSuccess() {
Intent intent = new Intent(SignUp.this, HomePage.class);
startActivity(intent);
finish();
}
public boolean validate() {
boolean valid = true;
if (name.isEmpty() || name.length() > 32) {
et_name.setError("please enter valid name");
valid = false;
}
if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
et_email.setError("please enter valid Email");
valid = false;
}
if (password.isEmpty() )
et_password.setError("please enter a valid password");
return valid;
}
public void initialise(){
name = et_name.getText().toString().trim();
email = et_email.getText().toString().trim();
password = et_password.getText().toString().trim();
cpassword = et_cpassword.getText().toString().trim();
}
}
The pattern that you are looking for looks like this:
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[##$%^&+=])(?=\\S+$).{4,}$
This is a complete pattern that should force the user to use digits, lower case, upper case and special characters.
You can use this following class.
public class Validation {
// Regular Expression
// you can change the expression based on your need
private static final String EMAIL_REGEX = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
//private static final String EMAIL_REGEX = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")#(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
private static final String PHONE_REGEX = "\\d{3}-\\d{7}";
private static final String ZIP_REGEX = "\\d{5}";
// Error Messages
private static final String REQUIRED_MSG = "required";
private static final String EMAIL_MSG = "invalid email";
private static final String PHONE_MSG = "###-#######";
private static final String ZIP_MSG = "#####";
public static boolean isEmailAddress(EditText editText, boolean required) {
return isValid(editText, EMAIL_REGEX, EMAIL_MSG, required);
}
public static boolean isPhoneNumber(EditText editText, boolean required) {
return isValid(editText, PHONE_REGEX, PHONE_MSG, required);
}
public static boolean isZip(EditText editText,boolean required){
return isValid(editText,ZIP_REGEX,ZIP_MSG,required);
}
public static boolean isValid(EditText editText, String regex, String errMsg, boolean required) {
String text = editText.getText().toString().trim();
editText.setError(null);
if ( required && !hasText(editText) ) return false;
if (required && !Pattern.matches(regex, text)) {
editText.setError(errMsg);
return false;
};
return true;
}
public static boolean hasText(EditText editText) {
String text = editText.getText().toString().trim();
editText.setError(null);
if (text.length() == 0) {
editText.setError(REQUIRED_MSG);
return false;
}
return true;
}
}
I am creating an android app (still the basic structure, without any design) from an Job site through XML feed using REST api.
Till now, I could managed to parse the XML data, displaying the List View with an POP UP menu item on each row. I am passing Data from PostBaseAdapter to MarkAsFav class. Could You please tell me if I am doing right or not? coz, I am getting no any data saved in database
Now, I have a problems:
I have 3 pop up menu item:
1. Set as Favourite
2. Share on Fb
3. email to Your friend
I am working on point number-1.
For now,I would be saving the data in SQLite Database itself. so, I am passing all the data (all the details about the job with all rows) to another activity, more over I am accepting a user given name to save the details through insertDB() in my Database.
But, unfortunately , nothing is getting saved in the database .
Can you tell me, if the data is getting passed or not and if the datas are being saved in database or not?
Please help me out. Please tell me where and how to modify the code?
DBHelper.java
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME ="MyDB.db";
public static final String JOBS_TABLE_NAME = "favourites";
public static final String JOBS_COLUMN_ID = "id";
public static final String JOBS_COLUMN_NAME = "name";
public static final String JOBS_COLUMN_HEADER="header";
public static final String JOBS_COLUMN_COMPANY="company";
public static final String JOBS_COLUMN_CITY="city";
public static final String JOBS_COLUMN_STATE="state";
public static final String JOBS_COLUMN_COUNTRY="country";
public static final String JOBS_COLUMN_FORMATEDLOCATION="formatedLocation";
public static final String JOBS_COLUMN_SOURCE="source";
public static final String JOBS_COLUMN_DATE="date";
public static final String JOBS_COLUMN_SNIPPET="snippet";
public static final String JOBS_COLUMN_URL="url";
public static final String JOBS_COLUMN_ONMOUSEDOWN="onmousedown";
public static final String JOBS_COLUMN_LATTITUDE="lattitude";
public static final String JOBS_COLUMN_LONGITUDE="longitude";
public static final String JOBS_COLUMN_JOBKEY="jobkey";
public static final String JOBS_COLUMN_SPONSORED="sponsored";
public static final String JOBS_COLUMN_EXPIRED="expired";
public static final String JOBS_COLUMN_FORMATTEDLOCATIONFULL="formattedLocationFull";
public static final String JOBS_COLUMN_FORMATTEDRELATIVETIME="formattedRelativeTime";
private HashMap hp;
public DBHelper(Context context)
{
super(context, DATABASE_NAME , null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(
"create table" + JOBS_TABLE_NAME +
"("+JOBS_COLUMN_ID+" integer primary key autoincrement, "+JOBS_COLUMN_HEADER+" text, "+JOBS_COLUMN_NAME+" text,"+JOBS_COLUMN_COMPANY+" text, "+JOBS_COLUMN_CITY+" text, "+JOBS_COLUMN_STATE+" text, "+JOBS_COLUMN_COUNTRY+" text,"+JOBS_COLUMN_FORMATEDLOCATION+" text,"+JOBS_COLUMN_SOURCE+" text,"+JOBS_COLUMN_DATE+" text,"+JOBS_COLUMN_SNIPPET+" text,"+JOBS_COLUMN_COMPANY+" text,"+JOBS_COLUMN_URL+"text,"+JOBS_COLUMN_ONMOUSEDOWN+" text,"+JOBS_COLUMN_LATTITUDE+" text,"+JOBS_COLUMN_LONGITUDE+"text,"+JOBS_COLUMN_JOBKEY+" text,"+JOBS_COLUMN_SPONSORED+" text,"+JOBS_COLUMN_EXPIRED+" text,"+JOBS_COLUMN_FORMATTEDLOCATIONFULL+" text,"+JOBS_COLUMN_FORMATTEDRELATIVETIME+" text)"
);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS favourites");
onCreate(db);
}
public boolean insertContact(String header, String name,String company,String city,String state,String country,String formattedLocation,String source,String date,String snippet,String url,String onmousedown,String lattitude,String longitude,String jobkey,String sponsored,String expired, String formattedLocationFull,String formattedRelativeTime)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
//contentValues.put("id",id);
contentValues.put(JOBS_COLUMN_HEADER,header);
contentValues.put(JOBS_COLUMN_NAME, name);
contentValues.put(JOBS_COLUMN_COMPANY, company);
contentValues.put(JOBS_COLUMN_CITY, city);
contentValues.put(JOBS_COLUMN_STATE, state);
contentValues.put(JOBS_COLUMN_COUNTRY, country);
contentValues.put(JOBS_COLUMN_FORMATEDLOCATION, formattedLocation);
contentValues.put(JOBS_COLUMN_SOURCE, source);
contentValues.put(JOBS_COLUMN_DATE, date);
contentValues.put(JOBS_COLUMN_SNIPPET, snippet);
contentValues.put(JOBS_COLUMN_URL, url);
contentValues.put(JOBS_COLUMN_ONMOUSEDOWN, onmousedown);
contentValues.put(JOBS_COLUMN_LATTITUDE, lattitude);
contentValues.put(JOBS_COLUMN_LONGITUDE, longitude);
contentValues.put(JOBS_COLUMN_JOBKEY, jobkey);
contentValues.put(JOBS_COLUMN_SPONSORED, sponsored);
contentValues.put(JOBS_COLUMN_EXPIRED, expired);
contentValues.put(JOBS_COLUMN_FORMATTEDLOCATIONFULL, formattedLocationFull);
contentValues.put(JOBS_COLUMN_FORMATTEDRELATIVETIME, formattedRelativeTime);
db.insert("favourites", null, contentValues);
return true;
}
public Cursor getData(int id){
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from favourites where id="+id+"", null );
return res;
}
public int numberOfRows(){
SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, JOBS_TABLE_NAME);
return numRows;
}
public boolean updateContact (Integer id, String name)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
db.update("favourites", contentValues, "id = ? ", new String[] { Integer.toString(id) } );
return true;
}
public Integer deleteContact (Integer id)
{
SQLiteDatabase db = this.getWritableDatabase();
return db.delete("favourites",
"id = ? ",
new String[] { Integer.toString(id) });
}
public ArrayList<String> getAllCotacts()
{
ArrayList<String> array_list = new ArrayList<String>();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from favourites", null );
res.moveToFirst();
while(res.isAfterLast() == false){
array_list.add(res.getString(res.getColumnIndex(JOBS_COLUMN_NAME)));
res.moveToNext();
}
return array_list;
}
}
MarkAsFav.java
public class MarkAsFav extends Activity {
private DBHelper mydb;
TextView header;
int id_To_Update = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mark_fav_layout);
header = (TextView) findViewById(R.id.editTextName);
mydb = new DBHelper(this);
Intent extras = getIntent();
if (extras != null) {
int Value = extras.getIntExtra("id",0);
if (Value > 0) {
//means this is the view part not the add contact part.
Cursor rs = mydb.getData(Value);
id_To_Update = Value;
rs.moveToFirst();
String nam = rs.getString(rs.getColumnIndex(DBHelper.JOBS_COLUMN_NAME));
if (!rs.isClosed()) {
rs.close();
}
Button b = (Button) findViewById(R.id.button1);
b.setVisibility(View.INVISIBLE);
header.setText((CharSequence) nam);
header.setFocusable(false);
header.setClickable(false);
}
}
}
public void run(View view) {
Intent extras = getIntent();
if (extras != null) {
int val = extras.getIntExtra("id",0);
String value1 = extras.getStringExtra("title");
String value2= extras.getStringExtra("company");
String value3= extras.getStringExtra("city");
String value4= extras.getStringExtra("state");
String value5= extras.getStringExtra("country");
String value6= extras.getStringExtra("formattedLocation");
String value7= extras.getStringExtra("source");
String value8= extras.getStringExtra("date");
String value9= extras.getStringExtra("snippet");
String value10= extras.getStringExtra("url");
String value11= extras.getStringExtra("onmousedown");
String value12= extras.getStringExtra("lattitude");
String value13= extras.getStringExtra("longitude");
String value14= extras.getStringExtra("jobkey");
String value15= extras.getStringExtra("sponsored");
String value16= extras.getStringExtra("expired");
String value17= extras.getStringExtra("formattedLocationFull");
String value18= extras.getStringExtra("formattedRelativeTime");
String headerValue = header.getText().toString();
Log.e("ERROR", "Inside run and checking Value and val");
if (val > 0) {
/*if (mydb.updateContact(id_To_Update, header.getText().toString())) {
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
Log.e("ERROR", "update error");
} else {
Toast.makeText(getApplicationContext(), "not Updated", Toast.LENGTH_SHORT).show();
}
}
else {*/
if (mydb.insertContact(headerValue, value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value14,value15,value16,value17,value18)) {
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
Log.e("ERROR", "insert contact errors");
} else {
Toast.makeText(getApplicationContext(), "not done", Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
}
}
PostBaseAdapter.java
public class PostBaseAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private ArrayList<Result> resultList;
private MainActivity mActivity;
private Context mContext;
String TAG="";
public PostBaseAdapter(Context context, ArrayList<Result> resultList) {
this.layoutInflater = LayoutInflater.from(context);
this.resultList = resultList;
this.mContext= context;
}
#Override
public int getCount() {
return resultList.size();
}
#Override
public Result getItem(int i) {
return resultList.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int i, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
final int j=i;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_item_post, null);
//viewHolder = new ViewHolder(convertView);
viewHolder= new ViewHolder();
//View overFlow = convertView.findViewById(R.id.id_overflow);
viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
viewHolder.imageClick= (ImageView) convertView.findViewById(R.id.id_overflow);
convertView.setTag(viewHolder);
//overFlow.setOnClickListener(new OverflowSelectedListener(mContext, mActivity));
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final Result result = resultList.get(i);
viewHolder.tvTitle.setText(result.getJobtitle());
final String jobTitle=resultList.get(i).getJobtitle();
final String company= resultList.get(i).getCompany();
final String city= resultList.get(i).getCity();
final String state= resultList.get(i).getState();
final String country= resultList.get(i).getCountry();
final String formattedLocation= resultList.get(i).getFormattedLocation();
final String source=resultList.get(i).getSource();
final String date= resultList.get(i).getDate();
final String snippet= resultList.get(i).getSnippet();
final String url= resultList.get(i).getUrl();
final String onmousedown= resultList.get(i).getOnmousedown();
final String lattitude= resultList.get(i).getLattitude();
final String longitude= resultList.get(i).getLongitude();
final String jobkey= resultList.get(i).getJobkey();
final String sponsored= resultList.get(i).getSponsored();
final String expired= resultList.get(i).getExpired();
final String formattedLocaionfull= resultList.get(i).getFormattedLocation();
final String formattedRelativeTime= resultList.get(i).getFormattedRelativeTime();
try {
viewHolder.imageClick.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.id_overflow:
final PopupMenu popup = new PopupMenu(mContext, v);
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
// Force icons to show
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
int id_To_Search = j + 1;
/*Intent intent = new Intent(mContext,MarkAsFav.class);
intent.putExtras(dataBundle);
mContext.startActivity(intent);*/
switch (item.getItemId()) {
case R.id.email_whatsapp:
doEmailOrWhatsapp(mActivity);
return true;
case R.id.share_on_fb:
shareOnFb(mActivity);
return true;
case R.id.mark_as_fav:
//viewHolder.
//dataBundle.putString("name", result.getJobtitle());
Intent intent = new Intent(mContext,MarkAsFav.class);
intent.putExtra("id",0);
intent.putExtra("title", jobTitle );
intent.putExtra("company",company );
intent.putExtra("city", city);
intent.putExtra("state",state );
intent.putExtra("country",country );
intent.putExtra("formattedLocation",formattedLocation );
intent.putExtra("source",source );
intent.putExtra("date", date);
intent.putExtra("snippet", snippet);
intent.putExtra("url", url);
intent.putExtra("onmousedown",onmousedown );
intent.putExtra("lattitude", lattitude);
intent.putExtra("longitude",longitude );
intent.putExtra("jobkey", jobkey);
intent.putExtra("sponsored",sponsored );
intent.putExtra("expired", expired);
intent.putExtra("formattedLocationFull",formattedLocaionfull );
intent.putExtra("formattedRelativeTime",formattedRelativeTime );
//intent.putExtras(dataBundle);
mContext.startActivity(intent);
return true;
default:
break;
}
return true;
}
});
//popup.show();
break;
default:
break;
}
}
});
}
catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
private class ViewHolder {
TextView tvTitle;//, tvPublishDate;
ImageView imageClick;
/* public ViewHolder(View item) {
tvTitle = (TextView) item.findViewById(R.id.tvTitle);*/
// imageClick=(ImageView)item.findViewById(R.id.id_overflow);
// tvPublishDate = (TextView) item.findViewById(R.id.tvPublishDate);
}
}
mark-fav-layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="370dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<EditText
android:id="#+id/editTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:ems="10"
android:inputType="text" >
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
android:onClick="run"
android:text="#string/save" />
</LinearLayout>
Result.java
public class Result {
public String jobtitle;
public String company;
public String city;
public String state;
public String country;
public String formattedLocation;
public String source;
public String date;
public String snippet;
public String url;
public String onmousedown;
public String lattitude;
public String longitude;
public String jobkey;
public String sponsored;
public String expired;
public String formattedLocationFull;
public String formattedRelativeTime;
public String getJobtitle() {
return jobtitle;
}
public void setJobtitle(String jobtitle) {
this.jobtitle = jobtitle;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getFormattedLocation() {
return formattedLocation;
}
public void setFormattedLocation(String formattedLocation) {
this.formattedLocation = formattedLocation;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getSnippet() {
return snippet;
}
public void setSnippet(String snippet) {
this.snippet = snippet;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getOnmousedown() {
return onmousedown;
}
public void setOnmousedown(String onmousedown) {
this.onmousedown = onmousedown;
}
public String getLattitude() {
return lattitude;
}
public void setLattitude(String lattitude) {
this.lattitude = lattitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getJobkey() {
return jobkey;
}
public void setJobkey(String jobkey) {
this.jobkey = jobkey;
}
public String getSponsored() {
return sponsored;
}
public void setSponsored(String sponsored) {
this.sponsored = sponsored;
}
public String getExpired() {
return expired;
}
public void setExpired(String expired) {
this.expired = expired;
}
public String getFormattedLocationFull() {
return formattedLocationFull;
}
public void setFormattedLocationFull(String formattedLocationFull) {
this.formattedLocationFull = formattedLocationFull;
}
public String getFormattedRelativeTime() {
return formattedRelativeTime;
}
public void setFormattedRelativeTime(String formattedRelativeTime) {
this.formattedRelativeTime = formattedRelativeTime;
}
public String getDetails() {
String result = jobtitle + ": " + company + "\n" + city + "-" + state
+ "\n" + country + "\n" + formattedLocation +"\n" + source+"\n"+date+
"\n"+snippet+"\n"+url+"\n"+onmousedown+"\n"+lattitude+"\n"+longitude+"\n"
+jobkey+"\n"+sponsored+"\n"+expired+"\n"+formattedLocationFull+"\n"+formattedRelativeTime;
return result;
}
}
I have just updated my code and its working fine for me. I am posting it here ,so that anyone can use if needed.
MarkFav.java
public class MarkAsFav extends Activity {
private DBHelper mydb;
TextView header;
int id_To_Update = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mark_fav_layout);
header = (TextView) findViewById(R.id.editTextName);
mydb = new DBHelper(this);
mydb.getWritableDatabase();
Bundle extras = getIntent().getExtras();
if (extras != null) {
int value = extras.getInt("id");
if (value > 0) {
//means this is the view part not the add contact part.
/* Cursor rs = mydb.getData(value);
id_To_Update = value;
rs.moveToFirst();
String nam = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));
if (!rs.isClosed()) {
rs.close();
}
Button b = (Button) findViewById(R.id.button1);
b.setVisibility(View.INVISIBLE);
header.setText( nam);
header.setFocusable(false);
header.setClickable(false);*/
}
}
}
public void run(View view) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
int value = extras.getInt("id");
String headerValue = header.getText().toString();
String value1 = extras.getString("title");
String value2 = extras.getString("company");
String value3 = extras.getString("city");
String value4 = extras.getString("state");
String value5 = extras.getString("country");
String value6 = extras.getString("formattedLocation");
String value7 = extras.getString("source");
String value8 = extras.getString("date");
String value9 = extras.getString("snippet");
String value10= extras.getString("url");
String value11= extras.getString("onmousedown");
String value12= extras.getString("lattitude");
String value13= extras.getString("longitude");
String value14= extras.getString("jobkey");
String value15= extras.getString("sponsored");
String value16= extras.getString("expired");
String value17= extras.getString("formattedLocationFull");
String value18= extras.getString("formattedRelativeTime");
Log.e("ERROR", "Inside run and checking Value and val");
if (value > 0) {
/*if (mydb.updateContact(id_To_Update, header.getText().toString())) {
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
Log.e("ERROR", "update error");
} else {
Toast.makeText(getApplicationContext(), "not Updated", Toast.LENGTH_SHORT).show();
}
}
else {*/
if (mydb.insertContact(headerValue, value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value14,value15,value16,value17,value18)){
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
Log.e("ERROR", "insert contact errors");
} else {
Toast.makeText(getApplicationContext(), "not done", Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
}
}
DBHelper.java
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "MyDB.db";
public static final String JOBS_TABLE_NAME = "favourites";
public static final String JOBS_COLUMN_ID = "id";
public static final String JOBS_COLUMN_NAME = "name";
public static final String JOBS_COLUMN_HEADER="header";
public static final String JOBS_COLUMN_COMPANY="company";
public static final String JOBS_COLUMN_CITY="city";
public static final String JOBS_COLUMN_STATE="state";
public static final String JOBS_COLUMN_COUNTRY="country";
public static final String JOBS_COLUMN_FORMATEDLOCATION="formatedLocation";
public static final String JOBS_COLUMN_SOURCE="source";
public static final String JOBS_COLUMN_DATE="date";
public static final String JOBS_COLUMN_SNIPPET="snippet";
public static final String JOBS_COLUMN_URL="url";
public static final String JOBS_COLUMN_ONMOUSEDOWN="onmousedown";
public static final String JOBS_COLUMN_LATTITUDE="lattitude";
public static final String JOBS_COLUMN_LONGITUDE="longitude";
public static final String JOBS_COLUMN_JOBKEY="jobkey";
public static final String JOBS_COLUMN_SPONSORED="sponsored";
public static final String JOBS_COLUMN_EXPIRED="expired";
public static final String JOBS_COLUMN_FORMATTEDLOCATIONFULL="formattedLocationFull";
public static final String JOBS_COLUMN_FORMATTEDRELATIVETIME="formattedRelativeTime";
private HashMap hp;
public DBHelper(Context context)
{
super(context, DATABASE_NAME , null, 1);
}
#Override
/* public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(
"create table" + JOBS_TABLE_NAME +
"("+JOBS_COLUMN_ID+" integer primary key autoincrement, "+JOBS_COLUMN_HEADER+" text, "+JOBS_COLUMN_NAME+" text,"+JOBS_COLUMN_COMPANY+" text, "+JOBS_COLUMN_CITY+" text, "+JOBS_COLUMN_STATE+" text, "+JOBS_COLUMN_COUNTRY+" text,"+JOBS_COLUMN_FORMATEDLOCATION+" text,"+JOBS_COLUMN_SOURCE+" text,"+JOBS_COLUMN_DATE+" text,"+JOBS_COLUMN_SNIPPET+" text,"+JOBS_COLUMN_COMPANY+" text,"+JOBS_COLUMN_URL+"text,"+JOBS_COLUMN_ONMOUSEDOWN+" text,"+JOBS_COLUMN_LATTITUDE+" text,"+JOBS_COLUMN_LONGITUDE+"text,"+JOBS_COLUMN_JOBKEY+" text,"+JOBS_COLUMN_SPONSORED+" text,"+JOBS_COLUMN_EXPIRED+" text,"+JOBS_COLUMN_FORMATTEDLOCATIONFULL+" text,"+JOBS_COLUMN_FORMATTEDRELATIVETIME+" text)"
);*/
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(
"create table" + JOBS_TABLE_NAME +
"("+JOBS_COLUMN_ID+" integer primary key autoincrement, "+JOBS_COLUMN_HEADER+" Text, "+JOBS_COLUMN_NAME+" Text,"+JOBS_COLUMN_COMPANY+" Text, "+JOBS_COLUMN_CITY+" Text, "+JOBS_COLUMN_STATE+" Text, "+JOBS_COLUMN_COUNTRY+" Text,"+JOBS_COLUMN_FORMATEDLOCATION+" Text,"+JOBS_COLUMN_SOURCE+" Text,"+JOBS_COLUMN_DATE+" Text,"+JOBS_COLUMN_SNIPPET+" Text,"+JOBS_COLUMN_COMPANY+" Text,"+JOBS_COLUMN_URL+"Text,"+JOBS_COLUMN_ONMOUSEDOWN+" Text,"+JOBS_COLUMN_LATTITUDE+" Text,"+JOBS_COLUMN_LONGITUDE+"Text,"+JOBS_COLUMN_JOBKEY+" Text,"+JOBS_COLUMN_SPONSORED+" Text,"+JOBS_COLUMN_EXPIRED+" Text,"+JOBS_COLUMN_FORMATTEDLOCATIONFULL+" Text,"+JOBS_COLUMN_FORMATTEDRELATIVETIME+" Text)"
);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS favourites");
onCreate(db);
}
public boolean insertContact(String header, String name,String company,String city,String state,String country,String formattedLocation,String source,String date,String snippet,String url,String onmousedown,String lattitude,String longitude,String jobkey,String sponsored,String expired, String formattedLocationFull,String formattedRelativeTime)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
//contentValues.put("id",id);
contentValues.put(JOBS_COLUMN_HEADER,header);
contentValues.put(JOBS_COLUMN_NAME, name);
contentValues.put(JOBS_COLUMN_COMPANY, company);
contentValues.put(JOBS_COLUMN_CITY, city);
contentValues.put(JOBS_COLUMN_STATE, state);
contentValues.put(JOBS_COLUMN_COUNTRY, country);
contentValues.put(JOBS_COLUMN_FORMATEDLOCATION, formattedLocation);
contentValues.put(JOBS_COLUMN_SOURCE, source);
contentValues.put(JOBS_COLUMN_DATE, date);
contentValues.put(JOBS_COLUMN_SNIPPET, snippet);
contentValues.put(JOBS_COLUMN_URL, url);
contentValues.put(JOBS_COLUMN_ONMOUSEDOWN, onmousedown);
contentValues.put(JOBS_COLUMN_LATTITUDE, lattitude);
contentValues.put(JOBS_COLUMN_LONGITUDE, longitude);
contentValues.put(JOBS_COLUMN_JOBKEY, jobkey);
contentValues.put(JOBS_COLUMN_SPONSORED, sponsored);
contentValues.put(JOBS_COLUMN_EXPIRED, expired);
contentValues.put(JOBS_COLUMN_FORMATTEDLOCATIONFULL, formattedLocationFull);
contentValues.put(JOBS_COLUMN_FORMATTEDRELATIVETIME, formattedRelativeTime);
db.insert("favourites", null, contentValues);
return true;
}
public Cursor getData(int id){
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from favourites where id="+id+"", null );
return res;
}
/* public int numberOfRows(){
SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, JOBS_TABLE_NAME);
return numRows;
}*/
public boolean updateContact (Integer id, String name)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
db.update("favourites", contentValues, "id = ? ", new String[] { Integer.toString(id) } );
return true;
}
public Integer deleteContact (Integer id)
{
SQLiteDatabase db = this.getWritableDatabase();
return db.delete("favourites",
"id = ? ",
new String[] { Integer.toString(id) });
}
public ArrayList<String> getAllCotacts()
{
ArrayList<String> array_list = new ArrayList<String>();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from favourites", null );
res.moveToFirst();
while(res.isAfterLast() == false){
array_list.add(res.getString(res.getColumnIndex(JOBS_COLUMN_NAME)));
res.moveToNext();
}
return array_list;
}
}