In my android apps,i want to press edittext the follwing popup calculator shown.when i enter calculation and press "ok" button result will stored in edittext.how to do this?give me any example code?
thanks in advance..
Make an Activity that does all the Calculator functionality you need (I'll leave that as an excercise.. :P)
In your original Activity, on the click even of your EditText, call the Calculator Activity using startActivityForResult()
The Calculator Acitivity should use setResult(RESULT_SUCESS, simple_intent_with_result_as_extra)
When the Calculator Activity Exits, the onActivityResult will be called on your original Activity with that Intent you passed earlier.
Extract the result from the extras and display it in that EditText.
Related
I'm trying to develop an app which has two editText fields for entering location. So I made two java files
1.MapsActivity.java(with activity_maps.xml)
2.AutoComplete.java(with autocomplete.xml)
In MapsActivity while clicking the 'from' text field, it will open the AutoComplete activity and after clicking any of the suggestions in it will open a fresh MapsActivity and places the clicked item . Likewise for 'to' text field also.
I am using Intents to pass the clicked values. So at last, five activities are opened when the two text boxes are filled. When I click back button ,it is showing the auto complete activity used the previous time.
Question:
Is any other way to close a particular activity with same name running behind?
Is there any other way to pass values by super.backpressed(); ?
enter image description here
You can try using startActivityForResult() method. That way you can use the result from the second activity in the first and also you wouldn't need to start a new activity. You can read up on it here startActivityForResult
try to clear backstack/clear_top/single_top using the intent.
Just add/set flags in intent.
or
finish activity after startActivity.
or
you can override the onBackPressed method to call the specific activity.
I'm currently programming an app where you should enter a text which is stored. The text should be able to be loaded in the app (maybe another activity) then.
It should be able to be used this way:
task.execute(new String[]{city,lang});
Is this makeable?
Thanks
You can use an Edittext on your first Activity on which user can type something.You can get that "something" programmatically in the same activity as a string.Now if you want to avail that string to another activity then you can use an Intent from the first activity to the second activity which will avail that string in the second activity.
Suppose i am having an activity (let's say activity1) and i have given a command for doing some long process. Mean while i am starting another activity (activity2), during this time if the activity1 finishes the process and shows the result in an alert box, then how can i make this alert box of activity1 appear over activity2? What i have noticed is that, the alert box of activity1 is only visible when i move back to activity1. Is there any way to do this? Ignore if the question is irrelevant, as i am just a beginner in android.
Before using two activity, you have to save the state of the activity and restore the another activity while come front. This is easily done by onRetainNonConfigurationInstance() and getLastNonConfigurationInstance() method. Please refer this link.
with the topic name everyone should be confused let me explain my question.i have two activity in first activity there is two edit text and two button one button is next and other is set. if i enter some values in the edit text and press the next button it will go so next page. In the second page after making some process and come to the first page when i press a button from second activity the values in the edit text in the first Activity will be disappear.my question that is there any solution to make the edit text value remain same in the page even after coming from the other activity.
Use SharedPreferences to save the values in the edit text when the button is clicked, then reset them in onResume().
You could save your values in your EditTexts like so:
Intent i = new Intent();
i.putStringExtra("editText1","text to save");
and you could start the 2nd activity for a result. When you return from the second activity, you can retrieve the values by using the getStringExtra() method
Right now in my android app a user presses a button to go to another activity, and then must press the back button on android to return to the previous activity. Can I have a button on my app and write code to go to the previous activity?
As the easiest way, you code write a code where your current activity is closed on a particular event, say on a button press. the method to be called is finish()
This way, when your current activity is finished, you are taken back to your previous activity.
Yes Ofcourse. : See the vogella article