In my settings activity, I want to check if the Edittextpreference is empty, before exiting the activity, clicking on the android.R.id.home button or on the back button of the device. If the edittextpreference is empty, I have to do something, like change its background color, and avoid the user to exit settings. But the problem is that if i have two edittextpreference, and only one is empty, one edittextpreference has to be with different background, and the other needs to be as it was.
Is there any way to do this? Maybe if it is not possible using the equivalent of edittext.setError()?
Related
I have two activties:
activity_main,
activity_display
in the main_activity user enters his/her name and presses the toggle button to display.
that takes the user to display_activity page where the result is displayed.
if the user finds that he/she has entered the wrong info they can go back and edit.
here is where the problem starts
after pressing the toggle button - display
it goes to display_activity and displays but when I press "back" button I'm restarting the whole (first) main_activity again... no values are present...
even the toggle button that needs to be set to "reset" is again showing "display".
should i use something else instead of
startActivity(intend1);
i want to resume the (first) activity main not restart everything
Seems like your first activity uses results from second activity. you can use startActivityForResult. Here is a very good answer refer to it.
How to manage startActivityForResult on Android
In my app I dynamically create a list of buttons. The user should be able to click on them. A short click would select the buttom as the current item, while a long click should enter the editor for this item.
Now I wonder how I can determine and set the colors that i should use. My first idea was to simply read the background and textcolor and switch them, however I'm not sure if this would be really the appropriate way to do this. So I was wondering if there is a an appropriate way of how to retrieve colors.
Of course I could hardcode some colors, but I don't know what color scheme the user has set and they might not be visible in a good way.
Please note, that, since I have to create the buttons dynamically, I can not set it in the XML.
You could simply use a ToggleButton, so android will take care of marking a "clicked" button as selected.
Since ToggleButton is a View, it has a setOnLongClickListener(Listener)-method, which can be used to make the ToggleButton long-clickable.
I am learning android programming so be cool with me.
My question is, i am having for example 5 buttons.User clicks any one button out of 5 and clicks another button.So how to keep track of previously clicked button ids.So the 2nd button clicks output is based on the previous button.
Can any one throw me pointers on that.I am new to java and android.
I will recommend you to follow (Screen State) base approach; as below:
1.) Create Screen State class and assign each state a unique value.
2.) You should mention Screen state stack and the current screen state.
3.) when you press a button, call a OnstateChange() function. Which should determine the next screen (based on current screen and whether user moved forward or backward). If user moved backward, pop the screen from stack and mark it as current screen.
If you need to remember only the very last button you clicked, use a class member variable to remember something about it (the button's ID, or a numeric index, or something). You should set this member variable in the onClick() call corresponding to the button.
If you need to remember the entire history of clicked buttons, use a List implementation (ArrayList should be fine) and add() the information about the button (the button's ID, or a numeric index, or something) in the onClick() method corresponding to the button.
If you have different OnClickHandler's for each button, this is pretty straightforward. If you share an OnClickHandler, you will need to use some identifying property of the View you get passed in as an argument to onClick().
I have a button which is basically used for start/stop. So initially the text of the button is set to start. I attached a OnClickListener to it. So whenever it gets clicked i change its text. So if it was start it become stop and vice-versa.
The problem comes when i change my phone view from portrait to landscape or vice-versa the button text gets reset.
So for example I clicked the start button---it changed to stop. Now if I tilt my phone to change the view the button text gets set to start again.
Am I using the button in a wrong way?
You should save your button state. When screen orientation changes, onCreate is called and all your app variables are re-intitialized. Read more here http://developer.android.com/reference/android/app/Activity.html
No, you are using the button in the right way.
The thing what you are seeing is "configuration change". When you are tilting your device, Android recreating your activity and recreating all it's views (so, they getting default captions as them described in XML).
You need to do the
disable configuration changes for your Activity. To do so, add the following to your manifest's activity tag: android:configChanges="orientation|keyboardHidden". It is not suitable, if you have different layouts for landscape and portraint orientations, when you need to...
handle the configuration changes by overriding onSaveInsatnceState method of your Activity, save a state there and then use it in onCreate method.
See this article for further explanation
all,
We know on Andorid, for a EditText, by default, whenever the EditText is clicked, the soft keyboard pops up to let you enter text. When you click DONE, it closes out and put the text directly to the EditText.
Now, what I am trying to do is, instead of an EditText, I have an ImageView which is to let user enter some comment.(So the ImageView actually is an comment icon). I wish whenever the icon is clicked, it pops up the text editor with user previous entered text, again once the DONE is hit, it closes out and I can save whatever text there back to a string member of the Activity. Is that possible?
So far, all I've seen about InputMethodManager is on EditText control, If it is too complicated, I probably just put an EditText into a sperate Activity.
Thanks.
There are many solutions:
One is to use custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Second one is to use a transparent activity on top of that one.
Then you could use FrameLayout and insert another view in an exact position...
I think you should try the frist or second one. Every ImageView can be easily converted into a button by adding onClick event to it.