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

  • SEARCH
  • Home
  • 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 7663549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:04:57+00:00 2026-05-31T14:04:57+00:00

i have a problem here. I need it so if there is no text

  • 0

i have a problem here.
I need it so if there is no text in Either of my 2 textboxes that you wont beable to hit the button

my JAVA code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.teachme);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    Button teach = (Button)findViewById(R.id.btn_teach_send);
    teach.setOnClickListener(this);


}

@Override
public void onClick(View v) {
    switch(v.getId())
    {

        case R.id.btn_teach_send:
        {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://monaiz.net/get.php");

            String responseStr = "";

            try {
                TextView word = (TextView)findViewById(R.id.tv_teach_request);
                TextView answer = (TextView)findViewById(R.id.tv_teach_response);

                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
                nameValuePairs.add(new BasicNameValuePair("word", word.getText().toString()));
                nameValuePairs.add(new BasicNameValuePair("answer", answer.getText().toString()));
                nameValuePairs.add(new BasicNameValuePair("action", "teach"));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity( );

                responseStr = EntityUtils.toString( entity );

            } catch (Exception e) {
                // TODO Auto-generated catch block
            }

            if( responseStr.equals("ok") )
            {
                Toast.makeText(getApplicationContext(), "Poka just learned a new word!", Toast.LENGTH_LONG).show();
                try {
                    this.finish();
                } catch (Throwable e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
}

And then this is my xml code which is obv for the design of the app..

the button and the edit text stuff is in there

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"  >

    <ScrollView android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:isScrollContainer="true">
        <LinearLayout android:orientation="vertical" android:id="@+id/ll_teach" android:background="#ffffffff" android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="2.0dip" android:layout_weight="0.0">
                <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="50.0dip" android:src="@drawable/if_ask" />
            </LinearLayout>
            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">

                    <EditText android:gravity="top|left|center" android:maxLength="30" android:id="@+id/tv_teach_request" android:background="@drawable/mespeak" android:paddingLeft="23.0dip" android:paddingTop="6.0dip" android:paddingRight="28.0dip" android:paddingBottom="23.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="20.0dip" android:layout_marginRight="5.0dip" android:layout_alignParentTop="true" style="@style/TeachBubbleFont" />

            </LinearLayout>
            <LinearLayout android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="2.0dip" android:layout_weight="0.0">
                <ImageView android:layout_gravity="left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="40.0dip" android:src="@drawable/then_response" />
            </LinearLayout>
            <LinearLayout android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
                    <EditText android:gravity="top|left|center" android:maxLength="30" android:id="@+id/tv_teach_response" android:background="@drawable/pokaspeak" android:paddingLeft="28.0dip" android:paddingTop="6.0dip" android:paddingRight="23.0dip" android:paddingBottom="23.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="1.0dip" android:layout_marginRight="20.0dip" android:layout_alignParentTop="true" android:layout_alignParentRight="true" style="@style/TeachBubbleFont" />
            </LinearLayout>
            <RelativeLayout android:gravity="center_vertical" android:id="@+id/RelativeLayoutBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0">
                <Button android:id="@+id/btn_teach_send" android:layout_width="wrap_content" android:layout_height="35.0dip" android:text="@string/btn_teach_send" android:layout_centerInParent="true" />
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>
  • 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-31T14:04:58+00:00Added an answer on May 31, 2026 at 2:04 pm

    You just need to setenabled property of the button for this. If two textbox has no text then disable button and if they have text then enable button.

    Here’s example

    String str1, str2;
    
    str1 = word.getText().toString();
    str2 = answer.getText().toString();
    
    if(!(str1.equals("")) && !(str2.equals("")))
    {
      teach.setEnabled(true);
    }
    else
    {
      teach.setEnabled(false);
    }
    

    EDIT

    If you want to check as soon as any of edittext get changed then you need to use textchangelistner for that.

    Here I made small example for it. It enables button only when 2 edittext have any of text.
    Hope this will help you.

    public class TSActivity extends Activity {
    
         String str = "";
         String str1 = "";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            final Button btn = (Button)findViewById(R.id.btn);
            TextView txt = (TextView)findViewById(R.id.text);
            TextView txt1 = (TextView)findViewById(R.id.text1);
            btn.setEnabled(false);
    
    
            txt.addTextChangedListener(new TextWatcher() {
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
    
                    str = s.toString();
                    if( !(str.equals("")) && !(str1.equals("")) )
                    {
                        btn.setEnabled(true);
                    }
                    else
                    {
                        btn.setEnabled(false);
                    }
                }
            });
     /**************************************************************************************************/       
            txt1.addTextChangedListener(new TextWatcher() {
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub              
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub              
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
    
                    str1 = s.toString();
                    if( !(str.equals("")) && !(str1.equals("")) )
                    {
                        btn.setEnabled(true);
                    }
                    else
                    {
                        btn.setEnabled(false);
                    }
                }
            });
        }  
    }
    

    Thanks…

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

Sidebar

Related Questions

I have an interesting SQL problem that I need help with. Here is the
ok so i have this problem that i need to achieve...Here is my site
This is my first post here. I have a problem. I need to take
Ok, so here's the problem I have to solve. I need to write a
I need a little push in the right direction. Here's my problem: I have
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
We have a problem here. We need to translate a website into multiple language.
I have a text file that I need to analyze. The file contains a
I have a problem here. My Zend_Forms do not render in view script. Via
Using Rational ClearCase v. 7.0.1.1 with UCM, I have a problem here when using

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.