Subscribe to Dogstopper's Code Mania        RSS Feed
-----

Android - Writing a Keyboard Dialog

Icon 4 Comments
Recently, I was given a task that was not very well documented, or the documentation expected and assumed one thing, while in reality, I wanted another. I am writing an Android application for a science application and needed a scientific notation to be easy to input. This means that I need the keyboard by default to show up in numbers mode, but still allow symbols such as "e" to be allowed. I quickly learned that with the default android keyboard, you could not do this, as the inputType is what dictates where it starts. This means that in order to start the keyboard in number mode, it will also accept ONLY numbers.

I had to search for another way, and frankly, I didn't need another Keyboard JUST for scientific notation. And because SoftKeyboards are so complicated to write, I saved that for a later project. Instead, I made a Dialog that behaved like a Keyboard and, when clicked, the EditText would show this View:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/keypad"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:stretchColumns="*">
  
  <TextView android:id="@+id/keypad_output"
  			android:textSize="20dip"
	    	android:paddingTop="10dip"	    
	    	android:paddingLeft="2dip"
	    	android:paddingRight="2dip"	/>
  <TableRow>
  	<Button android:id="@+id/keypad_1"
  			android:text="1"/>
  	<Button android:id="@+id/keypad_2"
  			android:text="2"/>
  	<Button android:id="@+id/keypad_3"
  			android:text="3"/>
  </TableRow>
  <TableRow>
  	<Button android:id="@+id/keypad_4"
  			android:text="4" />
  	<Button android:id="@+id/keypad_5"
  			android:text="5" />
  	<Button android:id="@+id/keypad_6"
  			android:text="6" />
  </TableRow>
  <TableRow>
  	<Button android:id="@+id/keypad_7"
  			android:text="7" />
  	<Button android:id="@+id/keypad_8"
  			android:text="8" />
  	<Button android:id="@+id/keypad_9"
  			android:text="9" />
  </TableRow>
  <TableRow>
  	<Button android:id="@+id/keypad_decimal"
  			android:text="." />
  	<Button android:id="@+id/keypad_0"
  			android:text="0" />
  	<Button android:id="@+id/keypad_EE"
  			android:text="EE" />
  </TableRow>
  <TableRow>
  	<Button android:id="@+id/keypad_plus"
  			android:text="+" />
  	<Button android:id="@+id/keypad_minus"
  			android:text="-" />
  	<Button android:id="@+id/keypad_backspace"
  			android:text="←" />
  </TableRow>
  <RelativeLayout android:orientation="horizontal"
  				android:layout_width="fill_parent"
  				android:layout_height="wrap_content">
  				
  	<Button android:id="@+id/keypad_submit"
  			android:text="Submit" 
  			android:layout_alignParentRight="true"
  			android:layout_width="wrap_content"
  			android:layout_height="wrap_content"/>
  			
  	<Button android:id="@+id/keypad_cancel"
  			android:text="Cancel" 
  			android:layout_toLeftOf="@id/keypad_submit"
  			android:layout_width="wrap_content"
  			android:layout_height="wrap_content"/>
  			
  	<Button android:id="@+id/keypad_clear"
	  			android:text="Clear"
	  			android:layout_alignParentLeft="true"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content" />
  			
  </RelativeLayout>

</TableLayout>



And for Horizontal orientation:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/keypad"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent">
  
  <TextView android:id="@+id/keypad_output"
  			android:textSize="20dip"
	    	android:paddingTop="10dip"	    
	    	android:paddingLeft="2dip"
	    	android:paddingRight="2dip"	
	    	android:layout_width="fill_parent"
	    	android:layout_height="wrap_content"/>
	<LinearLayout android:id="@+id/first_row"
			android:orientation="horizontal"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_below="@id/keypad_output">
		<Button android:id="@+id/keypad_1"
	  			android:text="1"
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_2"
	  			android:text="2"
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_3"
	  			android:text="3"
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_4"
	  			android:text="4" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_5"
	  			android:text="5" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_6"
	  			android:text="6" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_7"
	  			android:text="7" 
				android:layout_weight=".1"
				android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
				
	  	<Button android:id="@+id/keypad_8"
	  			android:text="8" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_9"
	  			android:text="9" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_0"
	  			android:text="0" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	</LinearLayout>
  	
  	<LinearLayout android:id="@+id/second_row"
			android:orientation="horizontal"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_below="@id/first_row">
	  	<Button android:id="@+id/keypad_decimal"
	  			android:text="." 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_EE"
	  			android:text="EE" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:text=""
	  			android:layout_weight=".2"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"
	  			android:visibility="invisible"/>

	  	<Button android:id="@+id/keypad_plus"
	  			android:text="+" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  			
	  	<Button android:id="@+id/keypad_minus"
	  			android:text="-" 
	  			android:layout_weight=".1"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	  	
	  	<Button android:text=""
	  			android:layout_weight=".3"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"
	  			android:visibility="invisible"/>
	  			
	  			
	  	<Button android:id="@+id/keypad_backspace"
	  			android:text="Backspace" 
	  			android:layout_weight=".2"
	  			android:layout_gravity="right"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"/>
	</LinearLayout>
  	
  	<RelativeLayout android:id="@+id/third_row"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_below="@id/second_row">
	  	<Button android:id="@+id/keypad_submit"
	  			android:text="Submit" 
	  			android:layout_alignParentRight="true"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"
	  			android:width="125dp"/>
	  			
	  	<Button android:id="@+id/keypad_cancel"
	  			android:text="Cancel" 
	  			android:layout_toLeftOf="@id/keypad_submit"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"
	  			android:width="125dp"/>
	  	
	  	<Button android:id="@+id/keypad_clear"
	  			android:text="Clear"
	  			android:layout_alignParentLeft="true"
	  			android:layout_width="wrap_content"
	  			android:layout_height="wrap_content"
	  			android:width="125dp" />
	</RelativeLayout>
  			
</RelativeLayout>



So, two different layouts so that the dialogs both fit on the screen (I mean, what is the use of having to scroll on a keyboard). Now, the Java file does some cool things in that it holds the current text in it, and when asked to submit, it sends that text back to the calling EditText. If canceled, it does not. Here's THAT file:
public class Keypad extends Dialog implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private View keys[] = new View[18];
	private View keypad;
	private EditText masterText;
	private TextView currentText;
	
	/**
	 * This calls super(context) and saves the master.
	 * @param context
	 * @param editText
	 */
	public Keypad(Context context, EditText editText) {
		super(context);
		this.masterText = editText;
	}	
	
	/**
	 * Called when the Dialog wants to be shown. Here, the
	 * GUI is created and settings are set, if possible.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setTitle(R.string.keypad_title); 
		setContentView(R.layout.keypad); 
		
		// Get all the views and set the appropriate 
		// listeners on them.
		findKeys();
		setListeners();
		
		// Get the text from the master EditText
		if (masterText != null) {
			String text = masterText.getText().toString();
			if (text != null)
				currentText.setText(text);
		}
	}
	
	/**
	 * Called when the View is about to be stopped. A 
	 * reference to the master EditText and the current 
	 * value of the display needs to be saved.
	 */
	@Override
	public Bundle onSaveInstanceState() {
		Log.d("Keypad", "in onSaveInstanceState()");
		Bundle bundle = new Bundle();
		
		// Set these two settings.
		bundle.putInt("MASTER_ID", masterText.getId());
		bundle.putString("CURRENT_STRING", "" +currentText.getText());
		
		// Set all the other settings and return
		bundle.putAll(super.onSaveInstanceState());
		return bundle;
	}
	
	/**
	 * Called when the View needs to restore itself from
	 * a stopped state. The value of the display is restored
	 * and the masterText component is recreated.
	 */
	@Override
	public void onRestoreInstanceState(Bundle state) {
		Log.d("Keypad", "in onRestoreInstanceState()");
		
		// Get the masterText from Selector's Views.
		masterText = (EditText) this.getOwnerActivity().findViewById(state.getInt("MASTER_ID"));
		
		// Reset the current string
		currentText.setText(state.getString("CURRENT_STRING"));
		
		// Do everything else.
		super.onRestoreInstanceState(state);
	}
	
	/**
	 * This method sets an action to each button.
	 */
	private void setListeners() {
		for (int i = 0; i < keys.length; i++) {
			keys[i].setonclickListener(handler);
		}
	}

	/**
	 * This method adds all the views to the array of keys.
	 */
	private void findKeys() {
		keypad = findViewById(R.id.keypad);
		currentText = (TextView) findViewById(R.id.keypad_output);
		keys[0] = findViewById(R.id.keypad_1);
		keys[1] = findViewById(R.id.keypad_2);
		keys[2] = findViewById(R.id.keypad_3);
		keys[3] = findViewById(R.id.keypad_4);
		keys[4] = findViewById(R.id.keypad_5);
		keys[5] = findViewById(R.id.keypad_6);
		keys[6] = findViewById(R.id.keypad_7);
		keys[7] = findViewById(R.id.keypad_8);
		keys[8] = findViewById(R.id.keypad_9);
		keys[9] = findViewById(R.id.keypad_0);
		keys[10] = findViewById(R.id.keypad_decimal);
		keys[11] = findViewById(R.id.keypad_EE);
		keys[12] = findViewById(R.id.keypad_minus);
		keys[13] = findViewById(R.id.keypad_plus);
		keys[14] = findViewById(R.id.keypad_submit);
		keys[15] = findViewById(R.id.keypad_cancel);
		keys[16] = findViewById(R.id.keypad_backspace);
		keys[17] = findViewById(R.id.keypad_clear);
	}
	
	/**
	 * This handler defines all the actions of the buttons.
	 * The EE button displays an "e"; the cancel button 
	 * quits without saved changes; the submit button quits
	 * and saves changes. The backspace and clear buttons...
	 * well bacspace and clear.
	 */
	private View.onclickListener handler = new View.onclickListener() {
		
		@Override 
		public void onclick(View v) {
			if (v.getId() == R.id.keypad_EE) {
				currentText.append("e");
			}
			else if (v.getId() == R.id.keypad_cancel) {
				// Have to call removeDialog and not just 
				// dismiss() so that onCreate() will be 
				// recalled with up-to-date values
				getOwnerActivity().removeDialog(Selector.KEYPAD_DIALOG);
			}
			else if (v.getId() == R.id.keypad_submit) {
				masterText.setText(currentText.getText().toString()); 
				
				// Have to call removeDialog and not just 
				// dismiss() so that onCreate() will be 
				// recalled with up-to-date values
				getOwnerActivity().removeDialog(Selector.KEYPAD_DIALOG);
			}
			else if (v.getId() == R.id.keypad_backspace) {
				CharSequence fieldText = currentText.getText();
				currentText.setText(fieldText.subSequence(0, fieldText.length()-1));
			}
			else if (v.getId() == R.id.keypad_clear) {
				currentText.setText("");
			}
			else {
				currentText.append(((Button)v).getText());
			}
		}
	};

}


So all that looks good. However, I was still running into a pretty major problem. When I clicked on the EditText and it gained focus, the default SoftKeyboard kept showing up. I had to click twice to make my Keypad Dialog to show up (even when overriding onTouch() and onclick()). The Android documentation gives no samples on how to turn this functionality off, and only on how to make it "better". Well, that was a tad frustrating.

I tried this:
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(et.getWindowToken(), 0);



Which the documentation says is supposed to cause the Keyboard to go away. It didn't work. I also banished the keyboard in the Android Manifest file:
android:windowSoftInputMode="stateHidden"



Which also didn't work.

After about a day of Googling, I find out about the onCheckIsTextEditor() which is defined in the TextView class with a default of false. The standard EditText returns true, which indicates that this needs tp opens the softKeyboard. All you have to do to stop this default functionality is override EditText to return false on that method instead.

I would say Android needs to update their documentation to say this! Anyway, here is what I did:

public class NoIMEEditText extends EditText {

    public NoIMEEditText(Context context, AttributeSet as) {
        super(context, as); 
    }

	@Override 
    public boolean onCheckIsTextEditor() {
        return false;
    }   
	
}



That allows it to BE an EditText in appearance, but simply have no Keyboard. Now, the only thing that you need to do is to include an XML file and set the onTouch() and onclick() methods to start up the new Keypad class that we wrote at the start of this article. Here's the rest of the code:

<LinearLayout
	    android:orientation="vertical"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent">
    <com.example.NoIMEEditText android:id="@+id/editText"
	    	android:layout_width="fill_parent"
	    	android:layout_height="wrap_content"
	    	android:inputType="none"
	    />
</LinearLayout>



public class Selector extends Activity implements onclickListener {
	
    /**
     * This is called when the activity is first created. It 
     * sets up the GUI for the user.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log.d("SELECTOR", "in onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        EditText edit = (EditText) findViewById(R.id.editText);
       
        
        // Set the default keyboard to never show up and
        // to use the custom Dialog instead. This is to 
        // allow scientific notation keys to all appear together
        addIMEDialog(edit);
        
    }

    ... Other methods and stuff here
    /**
     * This method simply adds an onclick() and an onTouch() listener
     * to the EditText component which start the input dialog.
     * @param v The EditText that we are setting.
     */
    private void addIMEDialog(EditText v) {
    	final EditText et = v; 
    	
    	/**
    	 * This listener starts a Keypad Dialog when invoked.
    	 */
    	et.setonclickListener(new View.onclickListener() {
			
			@Override
			public void onclick(View v) {
				currentText = et;
				showDialog(KEYPAD_DIALOG);
			}
		});
    	
    	/**
    	 * This listener starts a Keypad Dialog when invoked.
    	 */
    	et.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return false;
			}
		});
			
    }

	/**
	 * This method is invoked whenever the Activity is 
	 * requested to start a Dialog. It is done in this 
	 * manner so that they are managed by the Android 
	 * lifecycle and don't disappear when the screen 
	 * is rotated.
	 * 
	 * However, the Dialogs must disassociate themselves
	 * from this Activity when they are done running 
	 * because they are dynamically created, not statically,
	 * and onCreate() will only be called on disassociated
	 * dialogs.
	 * 
	 * @param id This is the id of the dialog to create.
	 */
	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog d;
		switch(id) {
			
		case KEYPAD_DIALOG:
			Log.d("SELECTOR", "in case KEYPAD_DIALOG");
			d = new Keypad(this, currentText);
			break;
			
		default:
			d = null;
		}
		
		// Return the selected Dialog.
		return d;
    }



So, basically, it adds onclick() and onTouch() listeners to start a Keypad dialog when clicked. createDialog() is what makes them. Note that that is why we use removeDialog() in the Keypad class, so that onCreate() will be called again. if you simply dismiss() the dialog, the next instance will use the same EditText, even if it's not the one we're editing. How to make persistent dialogs is in the scope of another tutorial though.

Thanks for listening to this tutorial, and I hope that you learned something ambiguous about the Android OS.

4 Comments On This Entry

Page 1 of 1

Topher84 

19 May 2011 - 05:10 PM
I've run into similar issues w/ my Android programming. The API documentation is "alright" but if you need to get some obscure things done, you have to dig around forums or be creative like you've done w/ your own keypad activity implementation.
0

Dogstopper 

19 May 2011 - 05:28 PM
You'd think that Google would be able to write articles on stuff like this...oh well. Its a new, pioneering field. One is bound to run into issues of lack of material matter.

That's one reason I'm posting this. It's probably the only result on Google that has anything to do with my issue.

Glad you enjoyed the read. :)
0

Topher84 

19 May 2011 - 07:05 PM

Dogstopper, on 19 May 2011 - 06:28 PM, said:

You'd think that Google would be able to write articles on stuff like this...oh well. Its a new, pioneering field. One is bound to run into issues of lack of material matter.

That's one reason I'm posting this. It's probably the only result on Google that has anything to do with my issue.

Glad you enjoyed the read. :)



Yeah I learned all about google "documentation" when I was trying to implement GoogleTest C++ framework. Also, if you have to do map based android apps, DO NOT use the emulator. Quite a bit of functionality does not work on the emulator.
1

AssistiveTech 

06 June 2011 - 12:50 PM
Hi I've found your solution interesting and wanted to run on Eclipse/android addon. I've try to fellow your tutorial but I probably miss or mix up the files that needed to be created to run on android emulator.
See attachment and hopefully someone can pin point what I am doing wrong.
See the 3 java files that I've tried to use from the tutorial.

import java.io.Serializable;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class Keypad extends Dialog implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private View keys[] = new View[18];
	private View keypad;
	private EditText masterText;
	private TextView currentText;
	
	/**
	 * This calls super(context) and saves the master.
	 * @param context
	 * @param editText
	 */
	public Keypad(Context context, EditText editText) {
		super(context);
		this.masterText = editText;
	}	
	
	/**
	 * Called when the Dialog wants to be shown. Here, the
	 * GUI is created and settings are set, if possible.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//setTitle(R.string.); 
		setContentView(R.layout.keypad); 
		
		// Get all the views and set the appropriate 
		// listeners on them.
		findKeys();
		setListeners();
		
		// Get the text from the master EditText
		if (masterText != null) {
			String text = masterText.getText().toString();
			if (text != null)
				currentText.setText(text);
		}
	}
	
	/**
	 * Called when the View is about to be stopped. A 
	 * reference to the master EditText and the current 
	 * value of the display needs to be saved.
	 */
	@Override
	public Bundle onSaveInstanceState() {
		Log.d("Keypad", "in onSaveInstanceState()");
		Bundle bundle = new Bundle();
		
		// Set these two settings.
		bundle.putInt("MASTER_ID", masterText.getId());
		bundle.putString("CURRENT_STRING", "" +currentText.getText());
		
		// Set all the other settings and return
		bundle.putAll(super.onSaveInstanceState());
		return bundle;
	}
	
	/**
	 * Called when the View needs to restore itself from
	 * a stopped state. The value of the display is restored
	 * and the masterText component is recreated.
	 */
	@Override
	public void onRestoreInstanceState(Bundle state) {
		Log.d("Keypad", "in onRestoreInstanceState()");
		
		// Get the masterText from Selector's Views.
		masterText = (EditText) this.getOwnerActivity().findViewById(state.getInt("MASTER_ID"));
		
		// Reset the current string
		currentText.setText(state.getString("CURRENT_STRING"));
		
		// Do everything else.
		super.onRestoreInstanceState(state);
	}
	
	/**
	 * This method sets an action to each button.
	 */
	private void setListeners() {
		for (int i = 0; i < keys.length; i++) {
			//keys[i].setonclickListener(handler);
		}
	}

	/**
	 * This method adds all the views to the array of keys.
	 */
	private void findKeys() {
		setKeypad(findViewById(R.id.keypad));
		currentText = (TextView) findViewById(R.id.keypad_output);
		keys[0] = findViewById(R.id.keypad_1);
		keys[1] = findViewById(R.id.keypad_2);
		keys[2] = findViewById(R.id.keypad_3);
		keys[3] = findViewById(R.id.keypad_4);
		keys[4] = findViewById(R.id.keypad_5);
		keys[5] = findViewById(R.id.keypad_6);
		keys[6] = findViewById(R.id.keypad_7);
		keys[7] = findViewById(R.id.keypad_8);
		keys[8] = findViewById(R.id.keypad_9);
		keys[9] = findViewById(R.id.keypad_0);
		keys[10] = findViewById(R.id.keypad_decimal);
		keys[11] = findViewById(R.id.keypad_EE);
		keys[12] = findViewById(R.id.keypad_minus);
		keys[13] = findViewById(R.id.keypad_plus);
		keys[14] = findViewById(R.id.keypad_submit);
		keys[15] = findViewById(R.id.keypad_cancel);
		keys[16] = findViewById(R.id.keypad_backspace);
		keys[17] = findViewById(R.id.keypad_clear);
	}
	
	public void setKeypad(View keypad) {
		this.keypad = keypad;
	}

	public View getKeypad() {
		return keypad;
	}

	

}


import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.onclickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;


public class Selector extends Activity implements onclickListener {
	
    private static final int KEYPAD_DIALOG = 0;

	/**
     * This is called when the activity is first created. It 
     * sets up the GUI for the user.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log.d("SELECTOR", "in onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        EditText edit = (EditText) findViewById(R.id.editText);
       
        
        // Set the default keyboard to never show up and
        // to use the custom Dialog instead. This is to 
        // allow scientific notation keys to all appear together
        addIMEDialog(edit);
        
    }

    //... Other methods and stuff here
    /**
     * This method simply adds an onclick() and an onTouch() listener
     * to the EditText component which start the input dialog.
     * @param v The EditText that we are setting.
     */
    private void addIMEDialog(EditText v) {
    	final EditText et = v; 
    	
    	/**
    	 * This listener starts a Keypad Dialog when invoked.
    	 
    	et.setonclickListener(new View.onclickListener() {
			
    		
		});
    	*/
    	/**
    	 * This listener starts a Keypad Dialog when invoked.
    	 */
    	et.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return false;
			}
		});
			
    }

	/**
	 * This method is invoked whenever the Activity is 
	 * requested to start a Dialog. It is done in this 
	 * manner so that they are managed by the Android 
	 * lifecycle and don't disappear when the screen 
	 * is rotated.
	 * 
	 * However, the Dialogs must disassociate themselves
	 * from this Activity when they are done running 
	 * because they are dynamically created, not statically,
	 * and onCreate() will only be called on disassociated
	 * dialogs.
	 * 
	 * @param id This is the id of the dialog to create.
	 */
	@Override
	protected Dialog onCreateDialog(int id) {
		
		Dialog d;
		switch(id) {
			
		
		case KEYPAD_DIALOG:
			Log.d("SELECTOR", "in case KEYPAD_DIALOG");
			EditText currentText = null;
			d = new Keypad(this, currentText);
			break;
			
		default:
			d = null;
		}
		
		// Return the selected Dialog.
		return d;
    }

	@Override
	public void onclick(DialogInterface arg0, int arg1) {
		// TODO Auto-generated method stub

		
	}
}



import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

public class NoIMEEditText extends EditText {

	public NoIMEEditText(Context context, AttributeSet as) {
		super(context, as);
	}

	@Override
	public boolean onCheckIsTextEditor() {
		return false;
	}

}


Plus the xml from tutorial.
When I run the program the emulator crash.
0
Page 1 of 1

December 2018

S M T W T F S
      1
2345678
91011121314 15
16171819202122
23242526272829
3031     

Recent Entries

Search My Blog

Recent Comments

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)