Date and hour on the phone in android? [closed] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Well, I want a Text view to resolve the date and the time of the phone, and then add it as a variable in my email intent to be sent. How do I do this? I dont event know where to start.

I want a Text view to resolve the date and the time of the phone
The current date and time of the device can be retrieved using Date date = new Date().
To display the date in a TextView using the user's default formatting:
String dateTime = DateFormat.getDateTimeInstance().format(date);
textView.setText(dateTime);
and then add it as a variable in my email intent to be sent
Assuming you want to include it in the message body:
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, textView.getText().toString());

Do you want to fetch the current data and time and show it in a textview without user intervention? If yes, you can do so using the below code
DateFormat dateFmt = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM);
String strDate = dateFmt.format(new Date());
and then you can show this string in your text view. and you can send the same in your email intent as part of your subject or body.

Related

I want to display the phone number entered by user during signup in the next activity [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i.e when the user enters his/her phone number ,the next activity should say : WE HAVE SENT AN OTP TO YOUR NUMBER ( WHERE INSTEAD OF NUMBER , IT SHOULD DISPLAY THE PHONE NUMBER ENTERED BY USER ) FOR MY ANDROID APP
open a new activity and send data through intent like this in your first activity :
val intent = Intent(context, MySecondActivity::class.java)
intent.putExtra("phoneNumber", myPhoneNumber)
context.startActivity(intent)
then in your second activity in onCreate():
phoneNumber = intent.extras?.getParcelable("phoneNumber")

How to use spinner to store values to Firebase? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am creating a Classified application, I am stuck at Post Activity, where the user needs to select the Category to post their products. Below is the rough sketch for Post Activity.
Firebase Database Structure :
How to let the user select the Category from the Category list and based on that Category the item/products needs to be saved under that Structure.
For example : If the user needs to post an Advertisement for Audi, he will select "Cars" from the spinner list and that info(image,price,name) should be saved under "Cars" structure in the Firebase Database. Any help would be appreciated, I need to know the logic behind this:
You can get spinner text like this.
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
After you got selected text you can set DatabaseReference location.
databaseReference = FirebaseDatabase.getInstance().getReference().child("All Categories").child(text);

Regular expression for song name in android [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
In my application I want to display the song's name. Now it is showing the entire song path, like this
String song_name = /storage/Music/Lean on.mp3
but I want to display only the song's name, that means
String song_name = Lean on.mp3
Can any one help me with the regular expressions used for extracting the name of song from the file path?
You can use subString function with combination of LastInedexOf function.
please find below example
String path=":/storage/Music/Lean on.mp3";
String filename=path.substring(path.lastIndexOf("/")+1);

How do I return an int from EditText and than show that number in Toast? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner at programming Android, please help with this simple project.
I want an integer to show up in toast, which I write in textBox. I do not know what to put in the highlighted part here.
Sorry for the link, but I cannot post the picture
You need to use the getText() method to get the text the user entered.
Change the myEdit declaration to:
final EditText myEdit = ... ;
and then use:
Toast.makeText(MainActivity.this, myEdit.getText().toString(), ...

How to get input from user for timer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I want to get user input of minutes/seconds for a timer
new CountDownTimer(30000, 1000) { }
The 30000 (30 second) value I want that from a user
t= (EditText)findViewById(R.id.time);
The value is stored in t
How do I achieve this?
new CountDownTimer(t, 1000) { }
This wont work...
You have to get the text from EditText from android convert it to long milliseconds.
t= (EditText)findViewById(R.id.time);
long userinput = Long.parseLong(t.getText().toString());
new CountDownTimer(userinput, 1000) { } ;
Though you have to do some input validation checking else you might get exception later on.
new CountDownTimer(t, 1000) { }
Here your t variable is EditText - its object and first parameter of CountDownTimer expects long so you need to get content of EditText and then parse it to long:
Long.parseLong(t.getText().toString());
Note: Also good practise is to validate input of User (input is not always correct you need to assume that User is "stupid" and can add some bullshit) if its correct number that can be parsed into long:
String input = t.getText().toString();
if (input.matches("\\d+")) {
// its valid number
Long.parseLong(t.getText().toString());
}
Or you can ensure it via XML when you'll specify inputType for EditText:
android:inputType="number"
t is EditText if you want get value in Long you must use:
Long.parseLong(t.getText().toString())
if you want any type else you must cast from t.getText.toString()

Categories

Resources