compiling text for textview, including data from SQLite table - android

A stupid question that Im sure is really really simple - ive been trying to fiddle to solve it myself, but its all very new to me so any wisdom would be REALLY appreciated!
With an android application (using eclipse) if I want to compile text for a text view using some data that is stored in a sqlite database (I have a working dbhelper and table I want to use), what do I do?
For example, I want a text box to say something like:
"hello"+#user_name+"its been"+#days+"since your last visit!"
where #user_name and #days are data in a table which I can currently retreive in a list (only 1 value in the list though).
How do i compile a string to be shown in the text view (and assign this string to the view)?
Help!

String textViewValue="hello "+nameList.get(0)+" its been "+daysList.get(0)+" since youy last visit";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(textViewValue);

You said you have stored it in arryalist right?
I am not sure if you have one ArrayList or two for Name and Days. (it would be good if you paste some of your code).
If your ArrayList is arrayList then you can get the name atleast like
"hello"+arrayList.get(0); // will retrive first element
Or best way use cursor and fire a query which will store output of following in curser
select Name,Days from your_table where Name='xyz';
then you can use folloing code to retrive data form curser (I am assuming there is only one row in cursor here)
if(cursor.moveToFirst()){
String s = "hello"+cursor.getString(0)+"Its been"+cursor.getString(1)+"days since your last visit!!";
}
now set this s in your textbox.

Related

How to upload text view from android to a database in a website using a button

I'm currently doing a project from one of my subjects in my university. I'm about to do an attendance app that checks if the professors are present, late, or absent in the room based on the schedule. I made an app in an android studio which uses radio groups and radio buttons that will change the text in the text view which will show if the professors attendance status. I'm thinking of making a button that will upload the text views with the attendance statuses to a website which holds the data(database).
I'm not used to programming in the android studio that is why I would like to know if a way to upload the text views on a website. Thanks
It's quite simple, You have to create Weg api that you can call from the android mobile application and pass the current status of the professor or the whatever you want to pass on the server. That api will update the database as per whatever you have passed from the mobile application.
Also, One more thing that you can not pass the text view, you just need to pass the text of that view.
I hope, you will get answer from this.
Happy coding...
Assign value of textview to a string variable.
And use this string in your api to pass data.
For example if you have a textview with name teacher, you can get its value using this line.
String st_teacher = teacher.getText();
Now use that st_teacher value in your api to upload data.

Android find Text Group and Highlight in ListView

I am performing a search over Strings in an ArrayList. If the Term is found I need to highlight that term and return the a string with the word where the term is present plus a word before and after that word!
Example:
Term = “some”
Searched String = “This is my awesome test String!”
Result = “my awesome test” (“some” should be highlighted here)
First off I am useless with RegEx and wouldn’t know where to start and secondly I’m not sure how to highlight text in a ListView, there are 3 TextViews per Row and I pass an Array with Data objects to the Adapter. Can I just give the Data Object Spanndable’s for highlighting?!
After some trial and error and some help i got this which seems to do the trick
(^|\S*\s)\S*term\S*($|\s\S*)

Should I use database for only two string? (Android-java)

I have two edittext and save button. When application is started, last data will coming. I know SQL ite database for it but can I use a text file or another thing. Is Sqlite correct always? And can I give example for save data from two edittext , and I get data to edittext.
Developers Guide says:
"If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs"

How to make number picker with only available numbers?

My app is using api 7. I don't know where to start with this challenge.
I have SQLite DB with some numbers stored between 1-99. Now I would like to make number picker for this range which would also remove numbers that are already in DB.
Create a list off the numbers 0-99, then do a query on your database. For every row in the results from the database, check if the list contains is (something like list.contains(number). If it is there, remove it (list.remove(item)) then proceed to the next row
You'll probably have to make your own widget. This will be somewhat involved, and since you are an Android beginner you might better spend your time coming up with a different input method.
In case you do decide to write your own widget, I would recommend extending LinearLayout, then inside of the constructor, doing something like this psuedocode:
setOrientation(VERTICAL);
addView ImageButton arrowUpButton;
addView EditText numberEditText;
addView ImageButton arrowDownButton;
arrowUpButton.setOnClickListener {
int num = myListOfInts.get(currentIndex++);
numberEditText.setText(num);
}
//vice versa for arrowDownButton
you'd also have to create a setter for the myListOfInts.
Good luck!

Delete one single cell from ContactsContract-ContentProvider

Hi fellow android programmers,
I wan't my application to delete one single information from a contact and I don't mean one phonenumber or one adress, I actually mean like only the street from the adress or only the job_description from the organization. Technically I won't to delete one cell of one row in the Data-Table of the ContactsContract-ContentProvider.
I red the documentation twice, but they are only talking about whole rows when they describe the insert-, update-, delete-, query-Methods :(
Is anyone aware of how to delete one particular cell? Or am I supposed to update one row with one cell so to "" (empty string)? Or do I even need to read one whole row, set the one cell to "" (empty string) and update the whole row?
Cheers and thanks in advance Ali3n
Do not delete it.. try to update it..
1) add your new value of particular column, like contentValues.put(STREET,"");
2) update the table by using update method. and use a where condition where contact_id = ur id.
PS:column names are not right.

Categories

Resources