Change functionality of back button [duplicate] - java

This question already has answers here:
Android - How To Override the "Back" button so it doesn't Finish() my Activity?
(10 answers)
Closed 5 years ago.
I have a recyclerView in a fragment which I use it to show some items. When selecting these items I change my toolbar title to number of selected items and also I change menu options. how can I make pressing back button cancel the selection operation?

You override the
onBackPressed()
Method and do what you want there. Any back key press will trigger this function and you'll be able to use your logic

Related

Dismiss Keyboard in Android Automatically [duplicate]

This question already has answers here:
Disable keyboard on EditText
(18 answers)
Closed 1 year ago.
I am trying to create calculator application in Android Studio using Java, I have EditText for showing result. When I focus this input Keyboard is showing. But I don't want to see keyboard in focus event as in normal calculator. Is there any way to solve this, or can I use other element either than EditText, I have used getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); in OnCreate method, but it doesn't work
EditText is desired to.. edit text. do you want to allow user for editing result?
if not just replace EditText with TextView and then any keyboard won't show up
if you still want this field to be editable then take a look a THIS QA, you will find there plenty of methods for blocking keyboard pop up automatically

Both click and longclick respond in listview [duplicate]

This question already has an answer here:
ListView Click and LongClick
(1 answer)
Closed 5 years ago.
I have implemented both onItemClickListener and onItemLongClickListener in my ListView.
- itemClick to start a new activity;
- itemLongClick to open a popup.
But when I longpress an item both listeners react.
How do I set OnClick not to respond when I longpress?
You need to return true in LongClick then onClick will not be called. Look at this: how to implement onItemLongClickListener and onItemClickListener event on listview row in android?
This question has been answered previously on this forum. :)

Make EditTexts not linked? [duplicate]

This question already has answers here:
Android Edittext question, replace keypad enter with done
(5 answers)
Closed 5 years ago.
I made an app with several EditTexts in my layout, and when I enter Something into the first, the keyboard will show a "next" arrow, to type in the next EditText. But I don't want that to happen. I want it to show a "finished" symbol, and exit the keyboard when I press it. How can I do that?
Add android:imeOptions="actionDone" to your EditText to acheive this.

I want the options menu when the menu button is clicked [duplicate]

This question already has answers here:
Android: How to enable/disable option menu item on button click?
(12 answers)
Closed 7 years ago.
I want the options menu with icons from the api level 11 when the menu button is clicked.If it is not possible after api level 10 then please suggest me how can I do this.
Thanks in advance.
The options menu is deprecated as of API 11; use the action bar or a navigation drawer instead. See: http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html

Beginner Android: Prompt to Leave [duplicate]

This question already has answers here:
How to show a dialog to confirm that the user wishes to exit an Android Activity?
(11 answers)
Closed 9 years ago.
When the user clicks the back button on the main activity, I would like a dialog to pop up asking the user if he "wants to leave". I am able to create the dialog and implement it but I am unsure of how to make the dialog open when the back button is pressed. Any Suggestions?
Which API? This is the easiest way from API 5+
#Override
public void onBackPressed () {
//super.onBackPressed();
dialog.show();
}

Categories

Resources