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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:59:46+00:00 2026-06-10T12:59:46+00:00

I can’t make Android onClick events work at all. I’ve rendered a TextView and

  • 0

I can’t make Android onClick events work at all. I’ve rendered a TextView and some buttons in activity_main.xml. In MainActivity.java I tryied to attach an onClick event to all buttons that will append their value to an input field. However, I’m having trouble finding some tutorials, books, etc on the subject of making dialers work. I have three books and none talk about using the call functions or making dialers. The tutorials I find online are all about people showing users how to root and theme their dialer, not how to program one. So my issues:

1) Where am I going wrong with appending a value to my Text view?
2) How will I remove the last value with the del onClick event?
3) How do I stop the Text view from pulling up the keyboard when a user clicks it? I.e. how to make it disabled/readonly (maybe) so only the buttons can update it?

Thanks for your help. In the below code I’ve cut the buttons down to one. All I’ve done is copy all the buttons and change the IDs, text, etc. So all the methods are the same but I can’t get just one button working. Again, please don’t laugh at me too hard for the code below.

activity_main.xml:

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

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/title_two"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:maxLength="15" >
    <requestFocus />
</EditText>

<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <Button
        android:id="@+id/one"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="1" />
    <Button
        android:id="@+id/two"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="2" />
    <Button
        android:id="@+id/three"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="3" />
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <Button
        android:id="@+id/four"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="4" />
    <Button
        android:id="@+id/five"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="5" />
    <Button
        android:id="@+id/six"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="6" />
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <Button
        android:id="@+id/seven"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="7" />
    <Button
        android:id="@+id/eight"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="8" />
    <Button
        android:id="@+id/nine"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="9" />
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <Button
        android:id="@+id/star"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="*" />
    <Button
        android:id="@+id/zero"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="0" />
    <Button
        android:id="@+id/pound"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="#" />
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <Button
        android:id="@+id/callButton"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="Call" />
    <Button
        android:id="@+id/contacts"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
        android:text="Con" />
    <Button
        android:id="@+id/del"
        android:layout_width="93dp"
        android:layout_height="wrap_content"
            android:text="Del" />
    </LinearLayout>

</LinearLayout>

And MainActivity.java:

package com.example.dialertest

import android.app.Activity;
import android.content.Intent;
import android.content.ActivityNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
Button oneBtn;
Button twoBtn;
Button threeBtn;
Button fourBtn;
Button fiveBtn;
Button sixBtn;
Button sevenBtn;
Button eightBtn;
Button nineBtn;
Button starBtn;
Button zeroBtn;
Button poundBtn;
Button callBtn;
Button conBtn;
Button delBtn;
EditText numTxt;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    oneBtn = (Button) findViewById(R.id.one);
    twoBtn = (Button) findViewById(R.id.two);
    threeBtn = (Button) findViewById(R.id.three);
    fourBtn = (Button) findViewById(R.id.four);
    fiveBtn = (Button) findViewById(R.id.five);
    sixBtn = (Button) findViewById(R.id.six);
    sevenBtn = (Button) findViewById(R.id.seven);
    eightBtn = (Button) findViewById(R.id.eight);
    nineBtn = (Button) findViewById(R.id.nine);
    starBtn = (Button) findViewById(R.id.star);
    zeroBtn = (Button) findViewById(R.id.zero);
    poundBtn = (Button) findViewById(R.id.pound);
    callBtn = (Button) findViewById(R.id.callButton);
    conBtn = (Button) findViewById(R.id.contacts);
    delBtn = (Button) findViewById(R.id.del);

    numTxt = (EditText) findViewById(R.id.editText1);

    oneBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            oneBtn.setText("1");
            numTxt.setText(numTxt.getText() + " " + oneBtn.getText());
            //numTxt.append("1");
        }
    });
/**private void performDial(String numberString) {
    if (!numberString.equals("")) {
        Uri number = Uri.parse("tel:" + numberString);
        Intent dial = new Intent(Intent.ACTION_CALL, number);
        startActivity(dial);
    }
}*/

/*private void call() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel: 8880000000"));
        startActivity(callIntent);
    } catch(ActivityNotFoundException e) {
        Log.e("Dialed Number","Call Failed", e);
    }
}
}*/
    }
}
  • 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-10T12:59:48+00:00Added an answer on June 10, 2026 at 12:59 pm

    change your onClicklistener to this :

    oneBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // no need to use onBtn here cuz the param v is the clicked View
            Button clickedButton = (Button) v;
            clickedButton.setText("1");
            numTxt.setText(numTxt.getText().toString() + " " + clickedButton.getText());
            //numTxt.append("1");
        }
    });
    

    Edittext’s getText() method returns an Editable Object, see :

    http://developer.android.com/reference/android/widget/EditText.html#getText()
    http://developer.android.com/reference/android/text/Editable.html

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

Sidebar

Related Questions

Can't work out a way to make an array of buttons in android. This
Can some one Guide me to work with these things... What is Model popup
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can someone please tell me why this wont work? I am getting error preg_match_all():
Can you please tell me how can I copy some lines of code in
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes

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.