Note that there are some explanatory texts on larger screens.

plurals
  1. POsetGravity not working
    text
    copied!<p>Please see my code below. I am unable to make SetGravity work.</p> <p>How come?</p> <p>Layout Code:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:padding="25dp" android:layout_width="match_parent" android:layout_height="match_parent" android:longClickable="true" android:orientation="vertical" &gt; &lt;EditText android:id="@+id/etCommands" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Type a command" android:password="true" /&gt; &lt;LinearLayout android:weightSum="100" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:layout_weight="20" android:id="@+id/btnResults" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Results" /&gt; &lt;ToggleButton android:paddingBottom="10dp" android:layout_weight="80" android:id="@+id/passTog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ToggleButton" android:checked="true"/&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/tvResults" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="invalid" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>java code:</p> <pre><code>public class TextPlay extends Activity { private static final String TAG = "MyApp"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.text); Button chkCmd = (Button) findViewById(R.id.btnResults); final ToggleButton passTog = (ToggleButton) findViewById(R.id.passTog); final EditText input = (EditText) findViewById(R.id.etCommands); final TextView display = (TextView) findViewById(R.id.tvResults); passTog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (passTog.isChecked()) { input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } else { input.setInputType(InputType.TYPE_CLASS_TEXT); } } }); chkCmd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String check = input.getText().toString(); Log.i(TAG, "Check Value is: " + check); if (check.contentEquals("left")) { Log.i(TAG, "I am under left "); display.setGravity(Gravity.LEFT); //WHYW ILL YOU NOT WORK SETGRAVITY????????????? } else if (check.contentEquals("center")) { display.setGravity(Gravity.CENTER); } else if (check.contentEquals("right")) { display.setGravity(Gravity.RIGHT); } else if (check.contentEquals("blue")) { display.setGravity(Gravity.RIGHT); } } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload