I Want to make my EditText empty when you put a new value. If I use a onClickListener I need first to focus and then to click (Double click), if I use onFocusChangeListener it is already deleting when click another EditText.
Does someone know a other way to achieve this (When first click == empty)?
Thanks in advance!
Don't make things complicated. Simply set android:selectAllOnFocus="true" to your EditText. So, when the user types-in some text and later click the text box, all the text inside will be highlighted - allowing user to type-in new text from scratch.
Related
I have 2 EditText and a button. When I click the button I want to print a text in the editText which is selected.. How I can do this??
Try to use this:
Get Cursor Position in Android in Edit Text?
In your onClick ask for the myEditText.getSelectionStart(); if is not null thats your EditText.
I hope this helps.
UPDATE
It looks more complicated than i thought at first, you are looking for a focus state. See if any of this answers helps you.
How can I detect focused EditText in android?
Please tell me how to hide the text on a button in android.
When I try this code, the button is hidden but I just want to hide the text on the button.
Button b= (Button)findViewById(R.id.follow);
b.setVisibility(View.GONE);
Please tell me how to solve this.
Thank you.
I have a suggestion if you want to setText to a button but don't want to show it.
Just set the text in the xml
android:text="TEXT"
then make font to 0
android:textSize="0sp"
text exist but can't be seen.
On your button use mButton.setTextScaleX(0); so the text will be hidden and to show use mButton.setTextScaleX(1);
If you just want to hide the Text and not the Button b.setVisibility(View.GONE) will not work.
It will hide the button itself and also button will not occupy any space in your layout as you are using View.GONE.
Using b.setText("") should help you setting just an empty text on Button.
May be you need to call invalidate()to refresh the UI.
First take backup of existing text on your button then clear button text to hide text. And to show text again reuse backup text :
Button b = (Button)findViewById(R.id.follow);
//Backup button text
String mButtonText = b.getText();
//Now hide text
b.setText("");
//To show text again
b.setText(mButtonText);
You can set the button text to just be blank instead of trying to hide the button.
Button button = (Button)findViewByID(R.id.ButtonID);
button.setText(" ");
This will allow you to change the text of the button within your source, so you will be able to change the button text when an event happens or even just set the button text to blank when it is created.
Button.setTextColor(getResources().getColor(android.R.color.transparent));
This will make the text transparent/hidden. It will keep the original size of the button and keep the original text.
on your xml. remove the android:txt=" " on your button.
Try this
<Button
android:text="TEXT"
android:textColor="#00000000"/>
general info:
#<alpha><red><green><blue>
all in hexadecimal 00 to ff
How do I focus on a particular part of a text upon making a new Activity in Android?
I have a long text appear on a new Activity upon clicking a button on a previous Activity. How do I start the screen from the second paragraph, third sentence of the third paragraph, so on? Thank you. :)
Like thus:
Click 'Read All' button from previous Activity -> Start from first paragraph
Click 'Section 1' button from previous Activity -> Start from second paragraph, but can still be scrolled upward to show first paragraph.
I hope someone gets what I'm saying! I don't exactly know how to search my problem because I cannot phrase it properly. Sorry if this was already asked. Thank you.
Requirement Every paragraph is an ListView item.
Pass the desired paragraph identifier with an Intent to the Activity. Read the identifier (and resolve it if required) and scroll to the according item with AbsListView#smoothScrollToPosition(int).
I have not tested it, but it could be possible that AdapterView#setSelection(int) jumps to the item immediately.
Well, there can be couple of ways to do it, as far as I am getting it -:
1) You can place your TextView inside ScrollView and then you can move the scroll to the middle(or what ever position you want to move) instead of starting.
2) You can make different variables which will contain partial and full text. And then on actions of your buttons you can assign those texts to respective TextViews.
For example, Your complete paragraph text is " Focus on a particular part of TextView, such that user can only see a part of it".
Now at first you only want to display a part of it. Let it be "Focus on a particular part of TextView".
Now you can save these two texts in two different variables like -:
String completeText = " Focus on a particular part of TextView, such that user can only see a part of it";
String partialText = " Focus on a particular part of TextView";
Now you can set the text of the TextView from 'partialText' variable and when user clicks 'Read more' button you can set its text from variable 'completeText'
Hope it helps. :-)
I have an android application that allows users to create edit text dynamically. However, it seems that whenever I have more than 5 edit text the typing process gets really lagging.
It goes by having a simple layout and a button. Whenever the button is clicked it runs this code:
EditText editText = new EditText(context);
myLayout.addView(editText);
Is there any way I can make the code more efficient such that it won't be slow?
I don't know if it's a good idea as I don't know the nature of your app, but declaring views in the xmls is usually faster. Try declaring a bulk of editTexts - according to your average application needs and set their visibility to GONE until the user chooses to add an editText and then you check if you have a GONE view - you set it to visible, If not, you add it via code.
Again, it all depends on your application's needs.
Try this:
EditText editText = new EditText(this);
myLayout.addView(editText);
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.