Please, somebody knows how I can set text in track part of switch button, I need to do this whith java code not with xml code.
enter image description here
Assuming this is for Android switch buttons you may use the following:
//sets text on creation
toggleButton.setText(textOff);
// Sets the text for when the button off.
toggleButton.setTextOff(textOff);
// Sets the text for when the button is on.
toggleButton.setTextOn(textOn);
Related
There are 20 JTextField and one calculate button in panel.
after entering data to text field and I click button, program calculate as well.
What I want to do, after first click for button, is there any updates in any text fields, button colors should be change as green (it means you have to know something already change and you have to calculate again).
How can I proceed with that, should I put action listener for each text field or any other short code exist?
Your question is not clear. As far my concern to yr question you can track button click event and put code there for check jtextfield value and on the bases of value you can take decision to change the color of the button
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 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.
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.