SQLite is not fetching text from TextView [duplicate] - android

This question already has answers here:
Converting TextView to String (kind of) Android
(2 answers)
Closed 5 years ago.
i am using sqlite and i have some textview in a xml file.The process is to fetch the text from textview and save those in database.But i am unable to fetch text from textview.why?
i.e. it fetches data from editText.

To fetch data from TEXT VIEW use
String text=textViewName.getText().toString();
now you can use the text string and send it to your database

Related

How to count word in TextView Android Studio [duplicate]

This question already has answers here:
how to count the number of words in Kotlin Android?
(5 answers)
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Suppose In my app I have two textview, first one name is ViewText and the second one is WordCount.
I want to show some text in ViewText and WordCount shows how many words in ViewText.
How can I count words in textview in Android Studio?
Try this one
val words = "Hi this is sentence for counting words"
var totalCount = words.split("\\s+".toRegex()).size
println(totalCount)

How to draw android spinner option from JSON [duplicate]

This question already has answers here:
How do I parse JSON in Android? [duplicate]
(3 answers)
Closed 5 years ago.
I am new to android development. I am stuck try to show dropdown's data into android . Data will come from server as a json format. I am using volley library for HTTP requests. Here is my volley response
{"blood_group_map":[{"value":"1","text":"O+"},{"value":"2","text":"O-"},{"value":"3","text":"A+"},{"value":"4","text":"A-"},{"value":"5","text":"B+"},{"value":"6","text":"B-"},{"value":"7","text":"AB+"},{"value":"8","text":"AB-"}]}
In this response I want draw blood_group_map key in Spinner option list like this HTML. Here value key is used for value and text key is used for display text.
<option value="1">O+</option>
Update:
I parsed this JSON but I want to send spiner value property to server and display text property. How can I send value to server not text ?
For Example if I select O+ blood group then I send spinner value 1 to server.
Use GSON parser to parse data to from json.
Basic working of GSON is: you build an object with structure same as your json.
All you have to do is pass it to spinner. An example of GSON parser here: GSON parser example
Spinner example: Spinner example

How to store array of integer in sharedPreferences [duplicate]

This question already has answers here:
Save ArrayList to SharedPreferences
(38 answers)
Closed 6 years ago.
I have an array integer in android studio like this { 0 , 0 , 0 , 1 , 1 , 0 , 1}
how can I store and recall it in shared preferences
There is no way you can store an array as it is.
Either you can convert it to JSON String and store it as a string.
Or you can store each element of the array individually with an ID like this.
Build a string out of it. Preferably using StringBuilder.
And, when reading, just split() on commas and then user Integer.parseInt() on all elements of the array.
Should be faster than the json route and does not require any extra dependency.

Can't match string which stored in SQLite [duplicate]

This question already has answers here:
String comparison - Android [duplicate]
(17 answers)
Closed 6 years ago.
In part of my application I get date from mobile and store it in SQLite Database as string.
when I try to select rows from database which have same date, can't find any match result.
Also as in below code, I tried to get specific cell of table which I'M sure it's match the current date. but no match.
is there any idea?
Get Date from mobile and insert it as string.
String currentDateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
MyDB.insertRow(currentDateString);
Check if date from database equal mobile date.
if (MyDB.getRow(21).getString(1).toString()==currentDateString)
Toast.makeText(getBaseContext(),"Match",Toast.LENGTH_SHORT).show();
You don't match Strings in Java using == operator. You use .equals() method as String is not a primitive type.
So try this -
if (MyDB.getRow(21).getString(1).toString().equals(currentDateString))
Strings aren't matched by == operator because it is an object.
try
MyDB.getRow(21).getString(1).toString().equals(currentDateString)
and if you need it not case sensitive
MyDB.getRow(21).getString(1).toString().equalsIgnoreCase(currentDateString)
Also
make sure that the inserted date format is the same that you match with

Android TextView to displays a number to two decimal places only through XML [duplicate]

This question already has answers here:
Round a double to 2 decimal places [duplicate]
(13 answers)
Closed 9 years ago.
I am populating a ListView using TextView as a row through SimpleCursorAdapter.The numbers in the TextView are displayed as say 8 or 2.6786 etc.I want them to be displayed as 8.00 or 2.67 etc.Can it be done through XML(like input Type method etc).Please suggest a wayout.
The question is bit different as under:
The codes are:
// THE DESIRED COLUMNS TO BE BOUND
columns = new String[] { slStock.KEY_SCRIPT, getColumnName(2),c.getColumnName(3)};
// THE XML DEFINED VIEWS FOR EACH FIELD TO BE BOUND TO
to = new int[] { R.id.tvstockscrpt, R.id.tvqty ,R.id.tvstockrate};
// CREATE ADAPTER WITH CURSOR POINTING TO DESIRED DATA
SimpleCursorAdapter cursAdapter = new SimpleCursorAdapter(this,R.layout.rowstock, c,columns, to);
lvstockdisplay.setAdapter(cursAdapter);
Here you will notice that the cursor c fetches data (from database query in background) and populates it in the ListView directly.The question is how can I format the cursor data for say the TextView whose id is(R.id.tvstockrate) and which is populated by c.getColumnNames(3).At which point in the codes the format statement can be inserted.
What about formatting the text when you set it?
yourTextView.setText(String.format("%.2f", value));
This could be your solution
yourTextView.setText(String.format("%.2f", value));

Categories

Resources