how to change a text of selected EditText (android) - java

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?

Related

how to get value of radio button and display on text view (Java for android)

enter image description here
this the XML structure for the radio button group
i try alot of code but nothnig good
In your Activity you will need to use findViewById to create Views in Java to connect to your layout RadioGroup and TextView. You will need to register a listener on your RadioGroup to detect changes to the selection and then pass the result to your TextView.
Provide the code you've tried and I'll update my answer with specific suggestions to help you fix it.

Hide the text on a button 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

Android: Make EditText empty when new value

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.

How to add clickable widgets in EditText at current position

I guess the title of the question is clear enough. What I want to do is add clickable widgets like Lable or Button or TextView in an EditText which already has some text in it. These widgets should get appended to the text.
As I don't know the exact number of the widgets to be added at design time, it won't be possible to do it in xml. I must do it in Java.
Thanks in advance.
Views just can be added to ViewGroups and EditText is not a ViewGroup, so you can't do that with default EditText widget, and you can write your own custom View to implement that.
this is the android documentation about custom views, and taking a look at this can be useful too.

Can I show up the textbox editor on an image icon in Android?

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.

Categories

Resources