Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:30:53+00:00 2026-05-27T18:30:53+00:00

Please see my code below. I am unable to make SetGravity work. How come?

  • 0

Please see my code below. I am unable to make SetGravity work.

How come?

Layout Code:

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <EditText
        android:id="@+id/etCommands"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Type a command"
        android:password="true" />


    <LinearLayout
        android:weightSum="100"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <Button
        android:layout_weight="20"
        android:id="@+id/btnResults"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Results" />

    <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"/>

    </LinearLayout>

    <TextView
        android:id="@+id/tvResults"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="invalid" />

</LinearLayout>

java 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);
                }

            }
        });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:30:54+00:00Added an answer on May 27, 2026 at 6:30 pm

    I just tested and it works.. You might be doing a few things wrong;

    First of all, when you type “left” into the text field, are you making sure that you didn’t type “Left” (most keyboards capitalize the first letter)

    If you are sure about the above, do you see the log that says “I am under left ” (Not the “Check is”)? If not, then it’s not getting there somehow..

    If you are indeed seeing it, you might want to clean/build your project (in Eclipse Project-> Clean -it does cleaning and re-building)

    If that doesn’t work neither, you might want to change your target build (change it to API level 10 or so) You don’t really need to worry about the target build if you are just using this as an exercise to learn.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see code below. The destructors are never called. Anyone know why and how
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
I am using vb.net code. I have grid view, please see the code below:
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',
I have a grid view control in my application. Please see the below code.
Please see my code below. ifstream myLibFile (libs//%s , line); // Compile failed here
Please see my code below... I am puzzled and want to initially show 30px
Please see the code below. I expect it to print either 10 because I
I'm trying to create a dynamic ItemizedOverylay (please see the code below) on Google
I am using struts 2.1.6 with ONGL. Please see the code below and tell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.