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 6701849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:58:59+00:00 2026-05-26T06:58:59+00:00

I am having an issue registering a call when a button is clicked. I

  • 0

I am having an issue registering a call when a button is clicked.

I have 2 EditTexts, one Button and one CheckBox. I would like to get the onClick() function called when the Button is pressed. Unfortunately, it only happens when the CheckBox is pressed, but it’s not the correct ID so I am confused.

Here is the java code:

Button connect = (Button) findViewById(R.id.connectToServer);
connect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    ....
}

As you can see, I look for the id “connectToServer”.

This is my .xml file:

<?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">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="#ffb6b6b6"
        android:textColor="#ffffffff" android:padding="2px" android:text="Settings" />
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:padding="13px">
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:textSize="25px"
            android:textColor="#ffffffff" android:text="Set server settings" />

        <TableLayout android:layout_marginTop="10px"
            android:stretchColumns="1" android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TableRow>
                <TextView android:text="IP address:" />

                <EditText android:id="@+id/serverIP" android:maxLength="15" />
            </TableRow>

            <TableRow>
                <TextView android:layout_marginTop="4px" android:text="Port:" />
                <EditText android:id="@+id/serverPort" android:maxLength="15" />
            </TableRow>

        </TableLayout>

        <LinearLayout android:layout_width="fill_parent"
            android:layout_marginTop="10px" android:orientation="horizontal"
            android:layout_height="fill_parent" android:gravity="center">
            <Button android:text="Connect" android:id="@+id/connectToServer"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </LinearLayout>
    </LinearLayout>

    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="#ffb6b6b6"
        android:textColor="#ffffffff" android:padding="2px"
        android:layout_marginTop="10px" android:text="Availability" />
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:padding="13px">
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:textSize="25px"
            android:textColor="#ffffffff" android:text="Set device available" />

        <TableLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
            <TableRow>
                <TextView android:layout_marginTop="10px"
                    android:layout_width="wrap_content" android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="Uncheck to disallow anyone from\nremotely connecting to the device." />
                <CheckBox android:id="@+id/checkbox" android:gravity="right"
                    android:checked="true" android:layout_weight="1"
                    android:layout_width="wrap_content" android:layout_height="fill_parent" />
            </TableRow>
        </TableLayout>
    </LinearLayout>
</LinearLayout>

The important line I believe would be this:

<Button android:text="Connect" android:id="@+id/connectToServer"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

but the code only gets called when the CheckBox button is checked or unchecked. I am not sure why that is.

Thank you very much!

  • 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-26T06:59:00+00:00Added an answer on May 26, 2026 at 6:59 am

    Try this,

    Button connect = (Button) findViewById(R.id.connectToServer);
    
    
    connect.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
    
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some issue with my function call please. I have a situation that I
Having an issue here that I have tried everything I can think of but
The issue I'm having is issue with is I'm trying to get the paintComponent
I am having issue setting a cookie to a web-service call in .NET. Before
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
We have a device that support SAE J1939 interface and having issue with finding
Having an issue, where calling WebRequest.GetResponse() hangs and times out on the first call,
Im having an issue with using prototypes observe function and gaining access to this
I am having issue in checking which input has been clicked using unobstructive javascript.
I am having issue with git pull.I have commited my changes in local repo.

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.