I'd like to add text to a working button. Currently, the code below prints the text at 0,0 rather than on the sprite button.
soundButton.graphics.beginFill(0xFFCC00);
soundButton.graphics.drawRect(0,900, 200, 50);
soundButton.graphics.endFill();
this.addChild(soundButton);
var soundtext:TextField = new TextField();
soundtext.text ="Sound On"; // default value
soundButton.addChild(soundtext);
soundButton.addEventListener( MouseEvent.CLICK,sound_CLICK);
Additionally, I'd like to add code to the listener below to have the button text reflect the state of the boolean doSound.
private function sound_CLICK (event:MouseEvent):Void {
doSound = !doSound;
// swap sprite button text Sound on/Sound off
}
Use the x and y property's of the Text Field to position the text on the button?
If there's something I'm missing ill update my answer.
Related
I have to mix colors in a view.Therefore I want to pass custom values to Color.rgb(0,0,255) function
Using Integer Variable will solve the above issue, But I am not able to pass the incremented value to my view.
A little description of what I want to do is:
View v; //to show the color by function Color.rgb()
int red,green,blue; //to change values of R,G,B respectively
int selectedColor = Color.rgb(red, green, blue) //used variable for color
v.setBackground(selectedColor)
//let's say I am increasing red value
Button add; // to increase red value
Button Sub; //to decrease red value
Now, I am stuck with the thing that when I am incrementing the value of red in onClick() function that value is not passing to {selectedColor = Color.rgb(red, green,blue)}. After Incrementing the value of red variable how to pass this red value to selectedColor Variable.?
You can simply use
Color.rgb()
or if you need to use alpha channel use
Color.argb()
So I have 6 edit texts and a button as shown below:
My question is how do I use the input from the EditTexts (which I have stored in content_main.xml) to do mathematical operations like calculating an average which I want to show up in a toast when the calculate button is pressed. I have already written some code in the MainActivity.java file that brings up a toast when the calculate button is pressed (also in content_main.xml), I just need to figure out how to use the inputs from the EditTexts in the toast.
EditText myText // = findViewById...
String text = myText.getText().toString();
What you should do first is to give each of its elements ID to also recognize from the Activity.
Then you should use the click event of the button
//Here it is referring to the id that gave his element in its layout
Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
And finally, like the button, get their input values EditText
//Here it is referring to the id that gave his element in its layout
EditText text = (EditText)findViewById(R.id.editText01);
And in order to do math, parse the string value remaining on a double (double for decimals can give the exact calculation if you want something, if you want to be an int approximately)
try{
Double value = Double.parseDouble(text);
}catch(NumberFormatException e){
//Message for error parse
}
I have an activity that is basically a long form of entry fields.
On each row, I want to show a TextView to serve as hint text just below each EditText and I want the TextView to remain visible at all times when the user is entering data. Unfortunately, the soft keyboard obscures the hint text and always positions itself immediately below the EditText. Is there any technique that will allow the TextView below the EditText to also be visible when the soft keyboard appears and the contents are adjusted (via windowSoftInputMode=adjustResize|adjustPan), without having the user scroll ?
Vishavjeet got me on the right track in suggesting I scrolldown to reveal the view that may be overlapped by the keyboard. Below is a function similar to what I used to solve the problem. It can be called when the EditText above the TextView receives focus:
// View targetView; // View that may be hidden by keyboard
// ScrollView scrollContainerView; // Scrollview containing hiddenView
//
void assureViewVisible (View targetView, ScrollView, scrollContainerView) {
Window rootWindow = activity.getWindow();
Rect rMyView = new Rect();
View rootview = rootWindow.getDecorView();
rootview.getWindowVisibleDisplayFrame(rMyView); // Area not taken up by keyboard
int subTextPos[] = new int[2];
targetView.getLocationInWindow(subTextPos); // Get position of targetView
int subTextHt = targetView.getHeight(); // Get bottom of target view
if ((subTextPos[1]+subTextHt) > rMyView.bottom) { // Is targetView at all obscured?
int scrollBy = (subTextPos[1]+subTextHt) - rMyView.bottom + 10; // add a small bottom margin
mMeasurementViewScrollView.smoothScrollBy(0, scrollBy); // Scroll to subtext
}
}
EDIT:
By understanding the problem more deeply, I think that you should add scroll programatically when user clicks on the Edittext. Here is the code to do that:
private final void focusOnView()
{
new Handler().post(new Runnable()
{
#Override
public void run()
{
your_scrollview.scrollTo(0, your_EditBox.getBottom());
}});
}
From my personal experience I think there is not such way to do that. The thing you can do is place the hint textview toRightOf the editext. Or Use modern Approach by using a Hint Placeholder on Edittext:
In XML, it's simply android:hint="someText"
Programatically you can use edittext.setHint(int);
pass R.string.somestring in above method.
I am creating a GenericListCellRenderer with Textfield, i need to edit the textfield and replace the values in it, but i didn't get any focus when clicking the Textfield. The code i tried was as follows.
public Container createGenericRendererContainer() {
Container c = new Container(new BoxLayout(BoxLayout.X_AXIS));
c.setUIID("Container");
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
c.addComponent(name);
TextField rollNo = new TextField();
rollNo.setFocusable(true);
rollNo.setUIID("TextField");
rollNo.setName("RollNo");
rollNo.setEditable(true);
rollNo.setEnableInputScroll(true);
rollNo.setEnabled(true);
c.addComponent(rollNo);
return c;
}
Henceforth, I need to get the action listener , that after i edited and press enter the values need to be changed in the database..
ListRenderer are stateless they are only used to display a list item on the list, if you need a Statefull Component don't use a List, use a box layout y Container instead.
Read this for more info - http://www.codenameone.com/blog/deeper-in-the-renderer
I'm Making simple app for project
That App contains lot of text so i want,
"when a button is pressed, text should Change in same layout"
like PowerPoint slide.
I want change text only not scroll.
Now i made my app, have lots of Windows or Layouts.
It is not looking good, too much layout in simple app so please help me .
Thanks in advance
Doing this is very easy, I will quickly walk you through the Algorithm:
Set a class level variable called as FLAG initialize it to 1.
Let us assume that FLAG = 1 will represent the first slide. FLAG = 2 the second slide and so on.
Now in your button click you can use a switch case or an if else condition, based on the value of the flag display the relevant text in textview.
Once done, increment the flag, for the next set of sentence(s).
Class level:
int FLAG = 1;
onCreate:
Initialize your textView:
TextView mtv = (TextView)findViewById(R.id.yourid);
Set a button click listener:
private View.OnClickListener slides = new View.OnClickListener() {
#Override
public void onClick(View v) {
if(FLAG ==1)
mtv.setText("First slide");
else if(FLAG ==2)
mtv.setText("Second Slide");
//and so on...
FLAG = FLAG+1;//increment flag
}
};