Android Application Development Tutorial - 29 - Set Gravity within Java

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Wow, I can't believed I can ever watch 29 youtube tutorial in a row!

ttttkk
Автор

If you want to make the input not canse senitive, you can replace all of the 'contentEquals(String str)' methods with 'equalsIgnoreCase(String str)' methods.

Alternativly, you can put "check = check.toLowerCase();' right before the first if-statement. This will work since the string we compare 'check' to (left, right and center) is all lowercase.

wade
Автор

The gravity issue: You should check the .xml in graphical layout if the blue box around that "invalid" text have enough room to move (to left, right).
I fixed puting a number in android:layout_width="250dp" instead of wrap_content or fill_parent
It´s only a matter of space.
You can put display.setText("left") inside of the "if (left)" statement to check if the code working properly, and the same for the right and center.

WilliamTanaka
Автор

I am beginner too, but this code works for me:

(IMPORTANT! LayoutParams must be

LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.LEFT;
tv.setLayoutParams(params);

emiljas
Автор

Thanks for this! Worked!
I think Gravity needs to be above fill parent. Maybe someone can post the logic behind this so we can *learn* why, rather than blundering around.

axydlbaaxr
Автор

Im not sure how to fix the simulator being slow but I have managed to get the keyboard working.
Open Android Device Manager - > Click your simulator -> Edit
Under Hardware; click New -> Select: 'Keyboard Support' -> Ok
Under the new Item listed in hardware, change the value of Keyboard support from 'no' to 'yes'


JethroLampitt
Автор

@justinrixx is your layout_width set to fill_parent?

strited
Автор

@igunIGN Yes you can use switch case: block instead of if statements

herp_derpingson
Автор

I would use check.toUpperCase() to upper case the String and whatever you are comparing have it in ALL upper case this is good programming techniques as all constants should be in all caps.

methooverload
Автор

instead of you should use
and you should use

MBserieHD
Автор

Thanks for saying your name this time...I could never remember it.

TamaraWirz
Автор

If you guys don't want it case sensitive, just use: check.equalsIgnoreCase()

HeyMyAwesomePeople
Автор

@justinrixx I have the same problem! Help is appreciated. Have done exactly like the tutorial but for some reason the setGravity doesnt change the gravity inside the textview :(

tjballe
Автор

@SkimpyDoughnut lol nvm xP
check that your findViewById are exactly same like in ur textplay.xml

mastermax
Автор

We can use switch(check) instead if statement?

amzaionutcatalin
Автор

i have a "yellow error" that states, "Hardcoded string...should use @string resource" what does that mean? Since the error is not red, I am still able to test launch the app...except I don't know if that "yellow error" will be a future problem. please help!

Akopyan
Автор

@justinrixx
so I did the next tutorial with this one and then everything worked perfectly including gravity with no crashing!!

Baaataaataaa
Автор

Wow man the password toggle is not working really smooth. I'm debugging it on my phone though (Galaxy Nexus, ICS), that might be why... but it still seems very strange. I can type without problems with password chars ON, but when i turn them off i can only type certain characters. It's really weird.

NikkexD
Автор

Hello guys, my application gives error (unfortunately has stopped) when I click the button "Try Command." What can be??

palmeirasdf
Автор

the String references to the EditText and the If/Else refer to the TextView, if this helps somebody

Varttino
join shbcf.ru