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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:44:22+00:00 2026-06-14T18:44:22+00:00

hello I have a big problem with a button on click and two edit

  • 0

hello I have a big problem with a button on click and two edit texts, I create my own keypad with twelve buttons and two edit text, the first edit text allow input number only and the second allow input number and do calculation. my real problem is that I can not input in the second edit text only in the first. here is a draw

        *********** *********
        *    1    * *   2   *   // These are EditTexts 
        *********** *********

        **************************
        *   7   *   8    *   9   *   
        **************************
        *   4   *   5    *   6   *  // These are Buttons
        **************************
        *   1   *   2    *   3   *
        **************************
        *   0   *   c    *   +   *
        **************************

(+) this button do the calculations and change the focus on the edit texts

also here is the code: thanks in advance I will appreciate any kind of help

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_cornuta);

         setupListView(); //set the list view
         inJugada = (EditText) findViewById(R.id.edit_x);
         inJugada.requestFocus();

         inValor = (EditText) findViewById(R.id.edit_y);

         inTotal = (EditText) findViewById(R.id.edit_z);
         inTotal.setText("");
         tv = (TextView) this.findViewById(R.id.textView2);  
         btnMensage = (ImageButton)findViewById(R.id.imageButton1);
         btnCombina = (Button)findViewById(R.id.button6);

         //Implementation for button 0123456789+delclr
         final Button bt0 = (Button) findViewById(R.id.btnNum0Id);
    bt0.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "0";
            }else if(inJugada.requestFocus() == false){
                numberDisplayed += "0";
            }

            updateTextField();

        }
    });

    final Button bt1 = (Button) findViewById(R.id.btnNum1Id);   
    bt1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "1";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "1";
            }
            updateTextField();

        }
    });

    final Button bt2 = (Button) findViewById(R.id.btnNum2Id);
    bt2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "2";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "2";
            }
            updateTextField();
        }
    });

    final Button bt3 = (Button) findViewById(R.id.btnNum3Id);
    bt3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "3";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "3";
            }
            updateTextField();
        }
    });

    final Button bt4 = (Button) findViewById(R.id.btnNum4Id);
    bt4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "4";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "4";
            }
            updateTextField();
        }
    });

    final Button bt5 = (Button) findViewById(R.id.btnNum5Id);
    bt5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "5";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "5";
            }
            updateTextField();
        }
    });

    final Button bt6 = (Button) findViewById(R.id.btnNum6Id);
    bt6.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "6";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "6";
            }
            updateTextField();
        }
    });

    final Button bt7 = (Button) findViewById(R.id.btnNum7Id);
    bt7.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "7";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "7";
            }
            updateTextField();
        }
    });

    final Button bt8 = (Button) findViewById(R.id.btnNum8Id);
    bt8.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "8";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "8";
            }
            updateTextField();
        }
    });

    final Button bt9 = (Button) findViewById(R.id.btnNum9Id);
    bt9.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if(inJugada.requestFocus() == true){
                playDisplayed += "9";
            }else if(inValor.requestFocus() == true){
                numberDisplayed += "9";
            }
            updateTextField();
        }
    });

    final Button btPlus = (Button) findViewById(R.id.btnAddId);
    btPlus.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if(inJugada.length() == 4){
                processPale();

            }else if(inJugada.length() == 2){
                processNum();

            }else if(inJugada.length() == 6){
                processTripleta();

            }

            //processNumbers();
            //showListViewData();
            updateTextField();
            plus = true;


        }

    });

    final Button btBs = (Button) findViewById(R.id.btnAtras);
    btBs.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (numberDisplayed.length() >= 1) {
                numberDisplayed = numberDisplayed.substring(0,
                        numberDisplayed.length() - 1);
            }

            if (playDisplayed.length() >= 1) {
                playDisplayed = playDisplayed.substring(0,
                        playDisplayed.length() - 1);
            }
            updateTextField();
        }
    });

    final Button btClear = (Button) findViewById(R.id.btnClearId);
    btClear.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            numberDisplayed = "";
            playDisplayed = "";
            storedNumber = "";
            plus = false;
            resultNumber = 0d;
            inValor.clearFocus();
            updateTextField();
            mData.clear();
            mAdapter.notifyDataSetChanged();
        }
    });


private void processNumbers() {

    if (plus) {
        resultNumber = calc.sum(Double.parseDouble(numberDisplayed),
                resultNumber); //create a sum
    }else{
        resultNumber = new Double(numberDisplayed);
    }
    numberDisplayed = "";
    updateTextField();
}
  • 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-06-14T18:44:23+00:00Added an answer on June 14, 2026 at 6:44 pm

    You want to use hasFocus() not requestFocus() because requestFocus() takes the focus away from whatever View currently has it and gives it to the caller. Also you should use a generic listener to reduce your duplicate code, like below.

    Create a new class variable:

    OnClickListener addClickListener = new OnClickListener() {
        public void onClick(View v) {
            int number = Integer.parseInt(((Button) v).getText().toString());
            if(inJugada.hasFocus()) { // " == true" is implied
                playDisplayed += number;
            }else if(inValor.hasFocus()) {
                numberDisplayed += number;
            }
            updateTextField();
        }
    };
    

    And add this listener to your Buttons 0-9:

    final Button bt0 = (Button) findViewById(R.id.btnNum0Id);
    bt0.setOnClickListener(addClickListener);
    
    // etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So hello everyone I have a big problem right now with a button that
Hello i have a big problem .. I'm creating a user login site but
Hello I have a little big problem in JavaFX application with terminating java process
Hello I have a UISegmentedControl with two segments. The selected segment is modified programmatically
I have a big problem (even my server's admin seems to have some difficulties
Hello i have here a big file and i need to replace some values
I have a really weird problem. The below code works fine if I create
I have big problem with basic of the Hibernate in all my projects. I
I have a big problem with std::wstring memory allocation. The program crash when I
I have a big problem and no idea how to solve it. I need

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.