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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:18:15+00:00 2026-06-08T17:18:15+00:00

How to enter data in my EditText using my own buttons instead of default

  • 0

How to enter data in my EditText using my own buttons instead of default keyboard (I mean like in calculator apps). Please write me some method or show suitable example. Thanks.
I initialize veriable, even tried to make some algorithm. But there is no reason to go further without knowing how to input data.
And of course I was looking for the answer.

public class MainActivity extends Activity implements OnClickListener{
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bPlus,bMin,bDiv,bMult,bEqual;
String sN1,sN2,func,result;
EditText etEnter;
SoundPool pool; int shot = 0;
TextView tvShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calculator);
    initVars();

}
private void initVars(){
    etEnter =(EditText)findViewById(R.id.etCalc);
    tvShow = (TextView)findViewById(R.id.tvShow);
     b0 = (Button)findViewById(R.id.button0);
     b1 = (Button)findViewById(R.id.button1);
     b2 = (Button)findViewById(R.id.button2);
     b3 = (Button)findViewById(R.id.button3);
     b4 = (Button)findViewById(R.id.button4);
     b5 = (Button)findViewById(R.id.button5);
     b6 = (Button)findViewById(R.id.butt6);
     b7 = (Button)findViewById(R.id.butt7);
     b8 = (Button)findViewById(R.id.butt8);
     b9 = (Button)findViewById(R.id.butt9);
    bMin = (Button)findViewById(R.id.bMinus); 
    bPlus = (Button)findViewById(R.id.bPlus);
    bDiv = (Button)findViewById(R.id.bDiv);
    bMult = (Button)findViewById(R.id.bMult);
    bEqual = (Button)findViewById(R.id.bEqual);
    b0.setOnClickListener(this);
    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
    b3.setOnClickListener(this);
    b4.setOnClickListener(this);
    b5.setOnClickListener(this);
    b6.setOnClickListener(this);
    b7.setOnClickListener(this);
    b8.setOnClickListener(this);
    b9.setOnClickListener(this);
    bMin.setOnClickListener(this);
    bPlus.setOnClickListener(this);
    bDiv.setOnClickListener(this);
    bMult.setOnClickListener(this);
    bEqual.setOnClickListener(this);

    pool = new SoundPool(5,AudioManager.STREAM_MUSIC,0);
    shot = pool.load(this, R.raw.shot, 1);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.button0:

        break;
    case R.id.button1:


        break;
    case R.id.button2:


break;
    case R.id.button3:

break;
    case R.id.button4:

        break;
    case R.id.button5:

break;
    case R.id.butt6:

        break;
    case R.id.butt7:

break;
    case R.id.butt8:

break;
    case R.id.butt9:

break;
    case R.id.bMinus:

func = "-";
break;
        case R.id.bPlus:

func = "+";
break;
        case R.id.bDiv:

func = "/";
break;
        case R.id.bMult:

            func = "*";
            break;
        case R.id.bEqual:
pool.play(shot, 1, 1, 0, 0, 1);
if(func.contentEquals("+")){
    if(sN1!=null && sN2!=null){
    long l1 = Long.parseLong(sN1);
    long l2 = Long.parseLong(sN2);
    long lRes = l1+l2;
    result = String.valueOf(lRes);
    tvShow.setText(result);
    }else if(sN1!=null && sN2==null){
        tvShow.setText(sN1);
    }
    sN1=sN2=null;
}else if(func.contentEquals("-")){
    if(sN1!=null && sN2!=null){
        long l1 = Long.parseLong(sN1);
        long l2 = Long.parseLong(sN2);
        long lRes = l1-l2;
        result = String.valueOf(lRes);
        tvShow.setText(result);
        }else if(sN1!=null && sN2==null){
            tvShow.setText(sN1);
        }
        sN1=sN2=null;
}else if(func.contentEquals("/")){
    if(sN1!=null && sN2!=null){
        long l1 = Long.parseLong(sN1);
        long l2 = Long.parseLong(sN2);
        long lRes = l1/l2;
        result = String.valueOf(lRes);
        tvShow.setText(result);
        }else if(sN1!=null && sN2==null){
            tvShow.setText(sN1);
        }
        sN1=sN2=null;
}else if(func.contentEquals("*")){
    if(sN1!=null && sN2!=null){
        long l1 = Long.parseLong(sN1);
        long l2 = Long.parseLong(sN2);
        long lRes = l1*l2;
        result = String.valueOf(lRes);
        tvShow.setText(result);
        }else if(sN1!=null && sN2==null){
            tvShow.setText(sN1);
        }
        sN1=sN2=null;
}

break;
}
}

and XML

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


<LinearLayout android:paddingTop="22dp" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" >
<EditText
    android:id="@+id/etCalc"
    android:layout_width="260dp"
    android:layout_height="60dp"
    android:layout_gravity="center"
    android:gravity="right"
    android:textSize="30dp"
    android:inputType="number" />
</LinearLayout>

<LinearLayout android:paddingRight="33dp" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" >
<TextView
    android:id="@+id/tvShow"
    android:layout_width="100dp"
    android:layout_height="45dp"
    android:text=":-)"
    android:textSize="35dp"
    android:paddingRight="10dp"
    android:layout_gravity="right"
    android:background="@drawable/rect_buttons"
    android:gravity="right"
    ></TextView>"
</LinearLayout>
 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"      android:gravity="center" android:paddingTop="20dp" >
<Button
    android:id="@+id/bPlus"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:textSize="30dp"
    android:gravity="center"
    android:text="+" />

<Button
    android:id="@+id/bMinus"
   android:layout_width="70dp"
    android:layout_height="50dp"
    android:textSize="30dp"
    android:text="-" />
 <Button
    android:layout_gravity="center"        
    android:id="@+id/bEqual"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:textSize="30dp"
    android:text="=" />

</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"    android:gravity="center" >

<Button
    android:id="@+id/button1"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="1"
    android:textSize="30dp" />
<Button
    android:id="@+id/button2"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="2"
    android:textSize="30dp" />
  <Button
    android:id="@+id/button3"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="3"
    android:textSize="30dp" />
</LinearLayout>

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"    android:gravity="center" >

<Button
    android:id="@+id/button4"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="4"
    android:textSize="30dp" />
<Button
    android:id="@+id/button5"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="5"
    android:textSize="30dp" />
  <Button
    android:id="@+id/butt6"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="6"
    android:textSize="30dp" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"    android:gravity="center" >

<Button
    android:id="@+id/butt7"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="7"
    android:textSize="30dp" />
<Button
    android:id="@+id/butt8"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="8"
    android:textSize="30dp" />
  <Button
    android:id="@+id/butt9"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:text="9"
    android:textSize="30dp" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"    android:gravity="center" >
<Button
    android:id="@+id/bDiv"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:textSize="30dp"
    android:text="/" />
<Button
    android:layout_gravity="center"        
    android:id="@+id/button0"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:textSize="30dp"
    android:text="0" />
<Button
    android:id="@+id/bMult"  android:layout_width="70dp"   android:layout_height="50dp" android:textSize="30dp" android:text="*" />

</LinearLayout>
</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-06-08T17:18:17+00:00Added an answer on June 8, 2026 at 5:18 pm

    You have to make your editText non focusable/editable and modify the text inside when you click on your buttons. Easy !

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

Sidebar

Related Questions

I have been using SESSION Variables to enter data with loginName as way to
how to Enter data from keyboard in shell programming ? some command similar to
We are using 2 edittext, one to enter hours and one to enter Minutes.
I have an editText that brings up the number keyboard. When you enter a
I have a scenario, for example, a EditText in acitivity instead of using Textview
I have a GridView which allows users to enter data using a EmptyDataTemplate. There
I want to hide soft keyboard on EditText even on 'click' also. I mean
I am trying to enter data through classes in a binary file using file
As I enter data into a TEXT column in my fusion tables, I find
I've created a HTML page to enter data to a MySQL database. I've embedded

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.