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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:33:39+00:00 2026-06-03T20:33:39+00:00

Currently I am developing an app based on a custom Keyboard. Basically I have

  • 0

Currently I am developing an app based on a custom Keyboard. Basically I have a layout with and edit text and a secondary xml with the keyboard layout. The app is supposed to launch, hide the default keyboard and show the custom one.

A couple of days ago I finished the app, I was testing it with AVDs with 2.1 2.2 and 2.3 all working like a charm!

After that I decided to try it on an actual device but the custom keyboard did’t work so I debugged it. The problem happens when setting the onclick listeners for the keys, they all throw nullPointerException.

What really puzzles me is that on the AVD it works perfectly, debugged it also for the AVD and no nullPointerException at all.

Is this normal?

The code following:

public class Main extends Activity implements OnTouchListener, OnClickListener,
    OnFocusChangeListener {
private EditText mEt;
private Button mBSpace, mBack, mBorrar;
private RelativeLayout mLayout, mKLayout;
private boolean isEdit = true; 
private int w, mWindowWidth;
private String cL[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
        "K", "L", "M", "N", "Ñ", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
        "X", "Y", "Z", ".", "?",  "!"}; 
private Button mB[] = new Button[40];

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        setContentView(R.layout.main);
        setKeys();  //get ids from xml and setOnClickListeners for every button.
        mEt = (EditText) findViewById(R.id.xEt);
        mEt.setOnTouchListener(this);
        mEt.setOnFocusChangeListener(this);
        mEt.setOnClickListener(this);
        mLayout = (RelativeLayout) findViewById(R.id.xK1);
        mKLayout = (RelativeLayout) findViewById(R.id.xKeyBoard);
        hideDefaultKeyboard(); //abrir teclado al prender app
        enableKeyboard();
        changeCapitalLetters();
        changeCapitalTags();

    } catch (Exception e) {
        Log.w(getClass().getName(), e.toString());
    }

}

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (v == mEt) {
        hideDefaultKeyboard();
        enableKeyboard();
    }
    return true;
}

@Override
public void onClick(View v) {

    if (v != mBack && v != mBorrar) {

        addText(v);

    } else if (v != mBorrar  && v == mBack) {
        isBack(v);
    } else if (v != mBack && v == mBorrar) {
        isBorrar(v);
    }
}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (v == mEt && hasFocus == true) {

        isEdit = true;

    } 

}

private void addText(View v) {
    if (isEdit == true) {
        String b = "";
        b = (String) v.getTag();
        if (b != null) {
            // adding text in Edittext
            mEt.append(b);

        }
    }

}

private void isBack(View v) {
    if (isEdit == true) {
        CharSequence cc = mEt.getText();
        if (cc != null && cc.length() > 0) {
            {
                mEt.setText("");
                mEt.append(cc.subSequence(0, cc.length() - 1));
            }

        }
    }

}
private void isBorrar(View v) {
    if (isEdit == true) {
        CharSequence cc = mEt.getText();
        if (cc != null && cc.length() > 0) {
            {
                mEt.setText("");
            }

        }
    }

}
private void changeCapitalLetters() {
    for (int i = 0; i < cL.length; i++)
        mB[i].setText(cL[i]);
}

private void changeCapitalTags() {
    for (int i = 0; i < cL.length; i++)
        mB[i].setTag(cL[i]);
}

// enabling customized keyboard
private void enableKeyboard() {
    mLayout.setVisibility(RelativeLayout.VISIBLE);
    mKLayout.setVisibility(RelativeLayout.VISIBLE);

}

// Disable customized keyboard
private void disableKeyboard() {
    mLayout.setVisibility(RelativeLayout.INVISIBLE);
    mKLayout.setVisibility(RelativeLayout.INVISIBLE);

}

private void hideDefaultKeyboard() {
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEt.getWindowToken(), 0);
    //imm.hideSoftInputFromWindow(mKLayout.getApplicationWindowToken(), 0);

}

//get ids del xml y setOnClickListeners
private void setKeys() {
    mWindowWidth = getWindowManager().getDefaultDisplay().getWidth();
    mB[0] = (Button) findViewById(R.id.xCero);
    mB[1] = (Button) findViewById(R.id.xUno);
    mB[2] = (Button) findViewById(R.id.xDos);
    mB[3] = (Button) findViewById(R.id.xTres);
    mB[4] = (Button) findViewById(R.id.xCuatro);
    mB[5] = (Button) findViewById(R.id.xCinco);
    mB[6] = (Button) findViewById(R.id.xSeis);
    mB[7] = (Button) findViewById(R.id.xSiete);
    mB[8] = (Button) findViewById(R.id.xOcho);
    mB[9] = (Button) findViewById(R.id.xNueve);
    mB[10] = (Button) findViewById(R.id.xA);
    mB[11] = (Button) findViewById(R.id.xB);
    mB[12] = (Button) findViewById(R.id.xC);
    mB[13] = (Button) findViewById(R.id.xD);
    mB[14] = (Button) findViewById(R.id.xE);
    mB[15] = (Button) findViewById(R.id.xF);
    mB[16] = (Button) findViewById(R.id.xG);
    mB[17] = (Button) findViewById(R.id.xH);
    mB[18] = (Button) findViewById(R.id.xI);
    mB[19] = (Button) findViewById(R.id.xJ);
    mB[20] = (Button) findViewById(R.id.xK);
    mB[21] = (Button) findViewById(R.id.xL);
    mB[22] = (Button) findViewById(R.id.xM);
    mB[23] = (Button) findViewById(R.id.xN);
    mB[24] = (Button) findViewById(R.id.xENIE);
    mB[25] = (Button) findViewById(R.id.xO);
    mB[26] = (Button) findViewById(R.id.xP);
    mB[27] = (Button) findViewById(R.id.xQ);
    mB[28] = (Button) findViewById(R.id.xR);
    mB[29] = (Button) findViewById(R.id.xS);
    mB[30] = (Button) findViewById(R.id.xT);
    mB[31] = (Button) findViewById(R.id.xU);
    mB[32] = (Button) findViewById(R.id.xV);
    mB[33] = (Button) findViewById(R.id.xW);
    mB[34] = (Button) findViewById(R.id.xX);
    mB[35] = (Button) findViewById(R.id.xY);
    mB[36] = (Button) findViewById(R.id.xZ);
    mB[37] = (Button) findViewById(R.id.xPUNTO);
    mB[38] = (Button) findViewById(R.id.xPREGUNTA);
    mB[39] = (Button) findViewById(R.id.xEXCLAMACION);
    mBorrar = (Button) findViewById(R.id.xBorrar);
    mBSpace = (Button) findViewById(R.id.xSpace);
    mBack = (Button) findViewById(R.id.xBack);
    for (int i = 0; i < mB.length; i++)
        mB[i].setOnClickListener(this);
    mBorrar.setOnClickListener(this);
    mBSpace.setOnClickListener(this);
    mBack.setOnClickListener(this);


}

}

And the layout files:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/xMLayout"
android:background="#000000" android:layout_height="fill_parent"
android:focusable="true"><!-- android:orientation="vertical"  -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:id="@+id/xsubLayout"
    android:keepScreenOn="true"
    android:layout_height="fill_parent"><!-- android:orientation="vertical"  -->
    <EditText android:id="@+id/xEt" android:layout_width="fill_parent"
        android:focusableInTouchMode="true" android:layout_height="wrap_content" />
    <!--<EditText android:id="@+id/et1" android:layout_width="fill_parent"
        android:layout_below="@+id/xEt" android:layout_height="wrap_content" />-->
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:id="@+id/xK1"
    android:layout_height="wrap_content"
    android:visibility="gone"> <!-- android:orientation="vertical"  -->
    <include android:id="@+id/xKeyBoard" layout="@layout/keyboard"></include>
</RelativeLayout>

The keyboard layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hebrwKeyboardView" android:layout_width="fill_parent"
android:layout_alignParentBottom="true" android:layout_below="@+id/xsubLayout"
android:orientation="vertical" android:background="#252625"
android:visibility="visible" android:layout_height="225sp">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="225sp"
    android:orientation="vertical" android:layout_alignParentBottom="true"
    android:clipChildren="true">
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content" android:layout_height="225sp"
        android:padding="0sp">
        <TableRow android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:padding="0sp">
            <LinearLayout android:baselineAligned="true"
                android:layout_width="fill_parent" android:layout_height="45sp"
                android:fitsSystemWindows="true">
                <Button android:soundEffectsEnabled="true" android:id="@+id/xCero"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="0" android:textColor="#000" android:tag="0"
                    android:padding="0sp" android:textStyle="bold" android:layout_gravity="center"/>
                <Button android:soundEffectsEnabled="true" android:id="@+id/xUno"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:padding="0sp" android:textColor="#000" android:tag="1"
                    android:text="1" android:textStyle="bold" android:layout_gravity="center" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xDos"
                    android:layout_gravity="center" android:layout_width="32sp"
                    android:padding="0sp" android:layout_height="fill_parent"
                    android:text="2" android:tag="2" android:textStyle="bold"
                    android:textColor="#000" android:fitsSystemWindows="true" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xTres"
                    android:layout_width="32sp" android:layout_gravity="center"
                    android:layout_height="fill_parent" android:text="3" android:tag="3"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:fitsSystemWindows="true" /><!--  android:ellipsize="marquee" /> -->
                <Button android:soundEffectsEnabled="true" android:id="@+id/xCuatro"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:layout_gravity="center_horizontal" android:text="4"
                    android:tag="4" android:fitsSystemWindows="true"
                    android:textColor="#000" android:textStyle="bold"
                    android:ellipsize="marquee" android:padding="0sp"/>
                <Button android:soundEffectsEnabled="true" android:id="@+id/xCinco"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:tag="5" android:layout_gravity="center" android:text="5"
                    android:fitsSystemWindows="true" android:textColor="#000" android:padding="0sp"
                    android:textStyle="bold" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xSeis"
                    android:layout_width="32sp" android:layout_gravity="center_horizontal"
                    android:layout_height="fill_parent" android:text="6" android:tag="6"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:fitsSystemWindows="true" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xSiete"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="7" android:fitsSystemWindows="true" android:tag="7"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xOcho"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="8" android:fitsSystemWindows="true" android:tag="8"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xNueve"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:textColor="#000" android:textStyle="bold" android:text="9"
                    android:fitsSystemWindows="true" android:tag="9" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
            </LinearLayout>
        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:padding="0sp">
            <LinearLayout android:baselineAligned="true"
                android:layout_width="fill_parent" android:layout_height="45sp"
                android:fitsSystemWindows="true">
                <Button android:soundEffectsEnabled="true" android:id="@+id/xA"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="A" android:textColor="#000" android:tag="A"
                    android:padding="0sp" android:textStyle="bold" android:layout_gravity="center"/>
                <Button android:soundEffectsEnabled="true" android:id="@+id/xB"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:padding="0sp" android:textColor="#000" android:tag="B"
                    android:text="B" android:textStyle="bold" android:layout_gravity="center" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xC"
                    android:layout_gravity="center" android:layout_width="32sp"
                    android:padding="0sp" android:layout_height="fill_parent"
                    android:text="C" android:tag="C" android:textStyle="bold"
                    android:textColor="#000" android:fitsSystemWindows="true" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xD"
                    android:layout_width="32sp" android:layout_gravity="center"
                    android:layout_height="fill_parent" android:text="D" android:tag="D"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:fitsSystemWindows="true" /><!--  android:ellipsize="marquee" /> -->
                <Button android:soundEffectsEnabled="true" android:id="@+id/xE"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:layout_gravity="center_horizontal" android:text="E"
                    android:tag="E" android:fitsSystemWindows="true"
                    android:textColor="#000" android:textStyle="bold"
                    android:ellipsize="marquee" android:padding="0sp"/>
                <Button android:soundEffectsEnabled="true" android:id="@+id/xF"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:tag="F" android:layout_gravity="center" android:text="F"
                    android:fitsSystemWindows="true" android:textColor="#000" android:padding="0sp"
                    android:textStyle="bold" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xG"
                    android:layout_width="32sp" android:layout_gravity="center_horizontal"
                    android:layout_height="fill_parent" android:text="G" android:tag="G"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:fitsSystemWindows="true" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xH"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="H" android:fitsSystemWindows="true" android:tag="H"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xI"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:text="I" android:fitsSystemWindows="true" android:tag="I"
                    android:textColor="#000" android:textStyle="bold" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xJ"
                    android:layout_width="32sp" android:layout_height="fill_parent"
                    android:textColor="#000" android:textStyle="bold" android:text="J"
                    android:fitsSystemWindows="true" android:tag="J" android:padding="0sp"
                    android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
            </LinearLayout>
        </TableRow>
        ...
...
        <TableRow android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:fitsSystemWindows="true"
            android:orientation="horizontal">
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="45sp" android:gravity="bottom"
                android:orientation="horizontal">
                <Button android:soundEffectsEnabled="true" android:id="@+id/xBorrar"
                    android:textColor="#000" android:textStyle="bold"
                    android:layout_width="115sp" android:layout_height="fill_parent"
                    android:tag="borrarTodo" android:text="BORRA_TODO" android:fitsSystemWindows="true" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xSpace"
                    android:textColor="#000" android:textStyle="bold"
                    android:layout_width="135sp" android:layout_height="fill_parent"
                    android:tag=" " android:text="|___ESPACIO___|" android:fitsSystemWindows="true" />
                <Button android:soundEffectsEnabled="true" android:id="@+id/xBack"
                    android:layout_width="70sp" android:layout_height="fill_parent"
                    android:textColor="#000" android:textStyle="bold" android:tag="back"
                    android:layout_gravity="center_horizontal|center_vertical|center"
                    android:fitsSystemWindows="true" android:text="BORRA" />
            </LinearLayout>
        </TableRow>
    </TableLayout>
</TableLayout>

The app is based on an example I downloaded from:
http://tutorials-android.blogspot.com/2011/06/create-your-own-custom-keyboard-for.html

Any help would be great, I don’t know what else to try right now…

  • 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-03T20:33:40+00:00Added an answer on June 3, 2026 at 8:33 pm

    I found what the problem was. The AVD I was using had a screen of 640×480 and used the standard layout xml. The physical device I used to test the app was a tablet with a screen of 800×600 and therefore targeted the layout-large xml which didn’t which didn’t have all the buttons.

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

Sidebar

Related Questions

I'm currently working on developing a custom keyboard app that will be optimized for
Good evening, In my app that I'm currently developing, I have a class that
i am currently developing an App based on iOS 5 on Xcode 4.2 .
I'm currently developing an iOS app and have reached the point where I need
I'm currently developing a simple text editing app for iPad using UITextView. I want
I am currently developing an app for iPhone. I have finished most of it,
I'm developing on an app that is location-based, I have a mapView set to
I'm working on a browser based app, currently I'm developing and styling for the
I am currently developing an App based on a Navigation Controller. However, when the
I am currently developing an app which will be on Android Market. How can

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.