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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:01:23+00:00 2026-06-01T14:01:23+00:00

I’m currently working on developing a custom keyboard app that will be optimized for

  • 0

I’m currently working on developing a custom keyboard app that will be optimized for a device using a DPad as its primary input device.

My problem is that When the cursor is in the EditText field and you press down (e.g. KEYCODE_DPAD_DOWN), the keyboard view is not receiving focus and KeyEvents. Either nothing happens, or the element beneath the EditText in question receives focus.

Below is the relevant code.

Any help would be much appreciated. I’ve tried dissecting the SoftKeyboard example aswell as KeyboardView.java for hints without success.

Thanks,
Bryan

MyKeyboard.java

public class MyKeyboard extends InputMethodService {

    private static final String TAG = "MyKeyboard";
    private MyKeyboardView mInputView = null;

    @Override public void onCreate() {
        super.onCreate();
    }

    @Override public View onCreateInputView() {
        mInputView = (MyKeyboardView) getLayoutInflater().inflate(R.layout.input, null);

        // attempts to make this focusable
        mInputView.setClickable(true);
        mInputView.setFocusableInTouchMode(true);
        mInputView.setFocusable(true);
        mInputView.setEnabled(true);

        return mInputView;
    }

    @Override public View onCreateCandidatesView() {
        super.onCreateCandidatesView();
        return null;
    }

    @Override public void onStartInputView(EditorInfo info, boolean restarting) {
        super.onStartCandidatesView(info, restarting);
    }

    @Override public void onFinishInput() {
        super.onFinishInput();
    }

    @Override public void onDestroy() {
        super.onDestroy();
    }
}

MyKeyboardView.java

public class MyKeyboardView extends TableLayout implements View.OnClickListener, View.OnFocusChangeListener {

    private static final String TAG = "MyKeyboardView";
    private ArrayList<Character> charList = new ArrayList<Character>();

    public MyKeyboardView(Context context) {
        super(context);

        populateKeyboard();
        this.setOnFocusChangeListener(this);
        this.setOnClickListener(this);
    }

    public MyKeyboardView(Context context, AttributeSet attrs) {
        super(context, attrs);

        populateKeyboard();
        this.setOnFocusChangeListener(this);
        this.setOnClickListener(this);
    }

    @Override
    public void onClick(View arg0) {
        Log.d(TAG, "onClick");
    }

    private void populateKeyboard() {
        charList.add(new Character(','));
        charList.add(new Character('.'));
        charList.add(new Character('?'));
        charList.add(new Character('<'));
        charList.add(new Character('>'));
        charList.add(new Character((char) 0x2798)); // arrow
        charList.add(new Character((char) 0x2798)); // arrow
        charList.add(new Character((char) 0x2798)); // arrow
        charList.add(new Character((char) 0x005F)); // underscore
        for(char c = '@'; c < 'Z'; c++) {
            charList.add(new Character(c));
            Log.d(TAG, "char: " + c);
        }


        TableRow tr = null;
        for(int i=0; i<charList.size(); i++) {
            if(i % 7 == 0) {
                if(tr != null)
                    this.addView(tr);
                tr = new TableRow(this.getContext());
                tr.setGravity(Gravity.CENTER_HORIZONTAL);
            }
            TextView tv = new TextView(this.getContext());
            tv.setPadding(21, 2, 21, 2);
            tv.setText(charList.get(i).toString());
            tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 22);
            tv.setTextColor(Color.WHITE);
            tv.setGravity(Gravity.CENTER);
            tv.setFocusable(true);
            tv.setEnabled(true);

            tr.addView(tv);
        }
        if(tr.getChildCount() > 0)
            this.addView(tr);
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        Log.d(TAG, "mInputView onFocusChange " + (hasFocus ? "true" : "false"));
    }
}

input.xml

<?xml version="1.0" encoding="utf-8"?>
<com.weirdtuesday.mykeyboard.MyKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#FF000000"
    android:focusable="true" />
  • 1 1 Answer
  • 1 View
  • 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-01T14:01:25+00:00Added an answer on June 1, 2026 at 2:01 pm

    Key events must be processed manually in the onKey method. To move the cursor, I use this:

    if (primaryCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            int position = connection.getTextBeforeCursor(Integer.MAX_VALUE, 0)
                    .length();
            final CharSequence selected = connection.getSelectedText(0);
            if (selected != null)
                connection.commitText(
                        mComposing.substring(0,
                                mComposing.length() - selected.length()), 1);
            else
                connection.commitText(mComposing, 1);
            connection.setSelection(position + 1, position + 1);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.