I have an empty activity with just the PlainText on it.
I want it so that after the user taps on the button that directs him to the empty activity it automatically selects/focuses on the PlainText bringing out the built-in android keyboard ready to get user's input.
I tried
android:focusedByDefault="true"
but that doesn't seem to do anything after going to the empty activity.
You can try to do
editText.requestFocus();
on your empty activity's onCreate() method
Set Focus on EditText
See here.
Note: Normally the general problem is "hot to remove auto focus" from EditText so it focuses automatically, so maybe you changed some attributes from your xml, please share your empty activity xml with us.
You can try to do
editText.setFocusableInTouchMstrong textode(true);
editText.setFocusable(true);
editText.requestFocus();
on your empty activity's onCreate() method
Related
I have a Fragment which has an EditText. I would like to override the behavior of the delete key in the EditText, but only for certain words. The logic of whether to override the delete event is held within the Fragment, and the EditText does not have access to the Fragment.
Example:
A user is typing: "Hello, my name is Adam and I am 23." The cursor is set immediately following "Adam", and the user taps the delete key. "Adam" is one of my keywords that should not be deleted, so I want to instead move the cursor to just before the word, and cancel the delete event.
Here is what I have tried so far:
OnKeyListener. This only works for hardware keyboards, and I need a solution for both virtual and hardware keyboards.
OnEditorActionListener. This does not trigger on a delete press.
Override the onCreateInputConnection method, with one of my creation which overrides the sendKeyEvent method. I can't do this because its creation must be inside the EditText (needs super access), but the logic of what words should not be deleted resides in the Fragment (which the EditText does not have access to). I cannot pass in the logic from the Fragment to the EditText because it is constantly changing.
TextWatcher. This successfully triggers before, while, and after text has been deleted, but cannot stop the deletion.
Any ideas that I have not yet tried would be much appreciated!
How would i resume the last viewed activity after the user has been closed the application. It is like, If the user open the application, the first activity will appear and when the user click the button it will proceed to the next activity, if he close the application and open again it will still show the last viewed activity. how would i do that? please help me.
Thank you,
I think you should use sharedpreferences. And in every activity you open, you have to put a value on your sharedpreference so that if you open again your application it will check the value of your shared preference then compare it, call the activity that fits the value you got. Hope it helps :)
You need to track his last activity then, keep it in a database and whenever he returns, look up his last activty in the database...the other way is cookies but not adviseable ....
Place this below line in AndroidManifest.xml for your activities in <activity/>.
android:launchMode="singleTask"
I am writing an android application with two EditText on the main activity. My problem is that once the main activity starts the soft keyboad automatically appears. I want the soft keyboard to appear only when the user clicks on the EditText component. How can I accomplish this?
In your activity, in your onCreate method, put the following
edittext.setFocused(false);
And then afterwards (in a different method, maybe an onClickListener for your edittext) put
edittext.setFocused(true);
Also you could put the below line in you manifest, in the the activity section, just below the android:name attribute
android:windowSoftInputMode="stateUnchanged"
Try this,
<EditText android:id="#+id/edit_text_id"
..
android:focusable="false" />
if you want to manage the inpt events , take a look on this part :
==> http://developer.android.com/guide/topics/ui/ui-events.html
I have an activity which gets a page from the web and then parses it to a TableLayout that is inside a ScrollView.
Then I save the ScrollView into a global variable just like its described by Jeff Gilfelt in this post.
After this I leave my activity and enter it again and I check if there is a saved ScrollView in the global variable, and if there is I try to set it via setContentView().
The problem is that I get an IllegalStateException on the setContentView(savedScrollView); call.
Can anyone help me?
When activity is resumed, chances are good that it is still configured and
does not need view setting. You shall set content view in onCreate() - not in onResume()
I am writing an Android app, part of which will be a survey involving multiple pages of checkbox question and answers. I have created an activity to display the question and options (from the DB) and what I want to do now is when i press the "Next" button it should just reload the current activity with the next question set from the database.
(the activity starts with survey.getNextQuestion() - so its just a case of refreshing the activity so it updates)
Im sure this is a simple thing to do -any ideas?
Thanks
Typically you would start a new instance of the activity for the new question. That way if the user hits back, it has the logical behavior of taking them back a page.
It is possible to update the same activity, but it is more complicated.
To open a new activity:
Intent intent = new Intent(this, MyActivity.class);
intent.putExtra("nextQuestion", x);
startActivity(intent);
Then in your onCreate method, you can pull the next question from the database.
Im sure this is a simple thing to do -any ideas?
It is pretty straight forward, yes. Mayra's answer is perhaps the better one, however here is an approach that will achieve the functionality you specified.
You can use findViewByID(int) to identify the View objects in your layout that need to be updated, and assign the result to an attribute in your onCreate to allow you to access it later.
E.g.
aView = (View) findViewById(R.id.aview);
Your survey.getNextQuestion() can obviously be used to get the next question.
The question can then be placed into the UI by manipulating the Views you obtained in onCreate.
E.g.
aView.setText("your question/answer");
Depending on the number of answers you may need to programatically create/remove checkbox Views from your layout
E.g.
ViewGroup yourViewGroup = findViewById(R.id.yourviewgroup);
View yourView = new View();
//Configure yourView how you want
yourViewGroup.addView(yourView);
youViewGroup.removeView(yourView);
All of this functionality can be contained in a function that is called by the onCreate method and when the next button is pressed.
Don't forget to store the result of the previous question before refreshing ;)