user5256621
user5256621

Reputation:

convert textView to string

TextView totalHours;
String TotalHours;
totalHours.setText(("Total hours : " + hours + ":" + minutes));

Assume the output is Totalhours :13:25

Now I want to convert the totalHours into String and save 13:25 into MySQL.

 TotalHours=totalHours.getText().toString();
 String[] time= TotalHours.split(":", 2);
 addInformation(time[1]);

Is this the correct way to convert a textView into String ?

Upvotes: 1

Views: 3363

Answers (4)

david ospina
david ospina

Reputation: 1

I had the same problem, and I tried with this:

String.valueOf(totalHours.getText());

If the first answer don't work for you, maybe this will help.

Upvotes: 0

TotalHours=totalHours.getText().toString();
String[] time= TotalHours.split(":");
String result= time[1]+time[2];
addInformation(result);

See if it helps.

Upvotes: 0

Sasi Kumar
Sasi Kumar

Reputation: 13358

Best you can directly store your variable hours ,minutes with String conversion.

  hours.toString();

or

String.valueOf(hours)

Upvotes: 3

Shiladittya Chakraborty
Shiladittya Chakraborty

Reputation: 4418

Yes. This is the correct way. Getting text from a TextView returns CharSequence. To convert CharSequence to String, toString() function is used.

Or you can directly store time in one string variable and insert it into MySql database.

Upvotes: 0

Related Questions