<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
	<channel>
		<title>Author at Infinum</title>
		<atom:link href="https://infinum.com/blog/author/nikola-gobovic/feed/" rel="self" type="application/rss+xml" />
		<link></link>
		<description>Building digital products</description>
		<lastBuildDate>Fri, 24 Apr 2026 14:02:14 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>

					<item>
				<image>
					<url>7891https://infinum.com/uploads/2020/11/input-connection-0.webp</url>
				</image>
				<title>Easy Custom Keyboard with InputConnection</title>
				<link>https://infinum.com/blog/input-connection/</link>
				<pubDate>Fri, 30 Oct 2020 17:31:00 +0000</pubDate>
				<dc:creator>Nikola Gobović</dc:creator>
				<guid isPermaLink="false">https://infinum.com/the-capsized-eight/input-connection/</guid>
				<description>
					<![CDATA[<p>An overlooked gem for creating a custom keyboard on Android.</p>
<p>The post <a href="https://infinum.com/blog/input-connection/">Easy Custom Keyboard with InputConnection</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</description>
				<content:encoded>
					<![CDATA[<div
	class="wrapper"
	data-id="es-210"
	 data-animation-target='inner-items'>
		
			<div class="wrapper__inner">
			<div class="block-blog-content js-block-blog-content">
	
<div class="block-blog-content-sidebar" data-id="es-92">
	</div>

<div class="block-blog-content-main">
	
<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-95"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-93">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-94'
	>
	As Android developers, we often find ourselves in need of creating custom components. One common case is creating a custom keyboard.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-98"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-96">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-97'
	>
	The first solution most devs probably think of involves creating a custom XML keyboard, gluing a bunch of on click listeners to it, and probably having a special custom logic on setting that same value to an <code>EditText</code> or some other view. Sounds like a lot of work.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-101"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-99">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-100'
	>
	Fortunately, there is an interface called <strong>InputConnection</strong>, which can really make our lives easier and save us a lot of time. It was added in API level 3, and appears to have remained unnoticed by many developers.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-104"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-102">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-103'
	>
	What is the InputConnection interface?</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-107"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-105">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-106'
	>
	As per documentation: <em>“The InputConnection interface is the communication channel from an InputMethod back to the application that is receiving its input. It is used to perform such things as reading text around the cursor, committing text to the text box, and sending raw key events to the application.“</em></p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-110"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-108">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-109'
	>
	Before further explanation, let’s take a look at two terms which might be useful in creating a bigger picture here:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-113"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="lists" data-id="es-111">
	<ul	class='typography typography--size-16-text-roman js-typography lists__typography'
	data-id='es-112'
	>
	<li><em>Input Method Engine</em> – can be anything that can produce any form of text represented information. In our case, that’s a keyboard.</li><li><em>Editor</em> – would represent any kind of <strong>component</strong> which is responsible for displaying the input produced from an Input Method Engine. In most cases, that would be a simple <code>EditText</code>.</li></ul></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-116"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-114">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-115'
	>
	So in layman’s terms, <code>InputConnection</code> acts as a glue between the <em>Input Method Engine</em> and an <em>Editor</em> which is responsible for displaying the input.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-119"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-117">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-118'
	>
	Now, enough of the chit chat and lets hop onto some examples.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-122"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-120">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-121'
	>
	Custom keyboard implementation</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-125"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-123">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-124'
	>
	Let’s assume we already have a custom keyboard XML layout prepared and now we’re deciding on which actions to take for connecting the keys with a certain <code>EditText</code> on the screen(or any class which subclasses a <code>TextView</code>).</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-128"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-126">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-127'
	>
	It would look approximately like this:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-131"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-media">
	<div	class="media block-media__media media__border--none media__align--center-center"
	data-id="es-129"
	 data-media-type='image'>

	<figure class="image block-media__image-figure image--size-stretch" data-id="es-130">
	<picture class="image__picture block-media__image-picture">
								
			<source
				srcset=https://infinum.com/uploads/2020/11/input-connection-1-1400x1050.webp				media='(max-width: 699px)'
				type=image/webp								height="1050"
												width="1400"
				 />
												<img
					src="https://infinum.com/uploads/2020/11/input-connection-1.webp"
					class="image__img block-media__image-img"
					alt=""
										height="1200"
															width="1600"
										loading="lazy"
					 />
					</picture>

	</figure></div></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-134"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-132">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-133'
	>
	To be able to use the InputConnection you need to have an <code>EditText</code> for which you can return/create its <code>InputConnection</code>:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-136"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-java github-light" data-language="java" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token">   val inputConnection </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #24292e;">currentlyFocusedEditText</span><span class="token">.</span><span class="token" style="color: #6f42c1;">onCreateInputConnection</span><span class="token">(</span><span class="token" style="color: #6f42c1;">EditorInfo</span><span class="token">(</span><span class="token">)</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-139"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-137">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-138'
	>
	<code>InputConnection</code> needs to have certain information about the <code>EditText</code> it’s connected to. So <a href="https://developer.android.com/reference/android/view/inputmethod/EditorInfo">EditorInfo()</a>’s job here would be to provide it. Most important type of information that EditorInfo() should provide are <strong>current cursor position</strong> and <strong>type of text content</strong>. There are plenty of other choices which might be handy, so feel free to check them out.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-142"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-140">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-141'
	>
	<em>Be careful if working with custom views and EditorInfo() as there could potentially be many things going wrong, so please do check official <a href="https://developer.android.com/reference/kotlin/android/view/inputmethod/EditorInfo">docs</a> in detail.</em></p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-145"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-143">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-144'
	>
	Now that we have <code>inputConnection</code> connected to its <code>currentlyFocusedEditText</code>, we can do some actions with it:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-147"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-java github-light" data-language="java" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token"> val inputConnection </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #24292e;">currentlyFocusedEditText</span><span class="token">.</span><span class="token" style="color: #6f42c1;">onCreateInputConnection</span><span class="token">(</span><span class="token" style="color: #6f42c1;">EditorInfo</span><span class="token">(</span><span class="token">)</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">private</span><span class="token"> val keyPadListener </span><span class="token" style="color: #d73a49;">=</span><span class="token"> OnClickListener </span><span class="token">{</span><span class="token"> view </span><span class="token" style="color: #d73a49;">-&gt;</span><span class="token">
</span></span><span class="line"><span class="token">         val value </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token">(</span><span class="token">view as</span><span class="token" style="color: #d73a49;">?</span><span class="token"> TextView</span><span class="token">)</span><span class="token" style="color: #d73a49;">?</span><span class="token">.</span><span class="token" style="color: #24292e;">text</span><span class="token">
</span></span><span class="line"><span class="token">         inputConnection</span><span class="token" style="color: #d73a49;">?</span><span class="token">.</span><span class="token" style="color: #6f42c1;">commitText</span><span class="token">(</span><span class="token">value</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">1</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-150"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-148">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-149'
	>
	As we’re dealing with a simple numpad, this would be the point in which we create a click listener to be able to react to certain keystroke actions. The main objective here would be to pass selected number values to the <code>currentlyFocusedEditText</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-153"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-151">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-152'
	>
	<code>InputConnection</code> gives us a simple way to achieve this with <em>commitText(String, int)</em> method:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-156"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="lists" data-id="es-154">
	<ul	class='typography typography--size-16-text-roman js-typography lists__typography'
	data-id='es-155'
	>
	<li><em>commitText</em>(<em>String, 1</em>) – textValue(String) will remove the contents of the currently composed text and replace it with the first parameter String(textValue).</li><li><em>commitText</em>(<em>textValue, Int</em>) – 1(Int) sets the new cursor position. If you pass an Integer value that is &lt;= 0 the cursor will be placed BEFORE the committed text. However, if you pass a 1 like in our case which is &gt; 0, then the cursor will be placed AFTER the committed text.</li></ul></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-159"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-157">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-158'
	>
	To make our implementation more complete we still need to take care of delete action. So, I suggest creating an <code>InputConnnection.delete()</code> extension function that would look approximately like this:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-161"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-java github-light" data-language="java" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #d73a49;">private</span><span class="token"> fun </span><span class="token" style="color: #24292e;">InputConnection</span><span class="token">.</span><span class="token" style="color: #6f42c1;">delete</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">        </span><span class="token" style="color: #6f42c1;">If</span><span class="token"> </span><span class="token">(</span><span class="token" style="color: #6f42c1;">getSelectedText</span><span class="token">(</span><span class="token" style="color: #005cc5;">0</span><span class="token">)</span><span class="token">.</span><span class="token" style="color: #6f42c1;">isNullOrBlank</span><span class="token">(</span><span class="token">)</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">            </span><span class="token" style="color: #6f42c1;">deleteSurroundingText</span><span class="token">(</span><span class="token" style="color: #005cc5;">1</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">0</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">        </span><span class="token">}</span><span class="token"> 
</span></span><span class="line"><span class="token">        </span><span class="token" style="color: #6f42c1;">commitText</span><span class="token">(</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">1</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">}
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-164"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-162">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-163'
	>
	Another cool feature of <code>InputConnection</code> is to fetch the selected text with a specific return option. With <em>getSelectedText(Int)</em>, the Int parameter serves as a flag to specify the return format. For example, the flag value of 0 would return the text as a regular String and <code>GET_TEXT_WITH_STYLES</code> would return a <code>SpannableString</code> with all the related styles.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-167"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-165">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-166'
	>
	If you’re wondering about <em>isNullOrBlank()</em> check, then <em>commitText(String,Int)</em> documentation should explain it: <em>“If there is no composing text when this method is called, the new text is inserted at the cursor position, removing text inside the selection if any.”</em></p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-170"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-168">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-169'
	>
	This is where <em>deleteSurroundingText(Int, Int)</em> method comes into picture:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-173"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="lists" data-id="es-171">
	<ul	class='typography typography--size-16-text-roman js-typography lists__typography'
	data-id='es-172'
	>
	<li>The first parameter specifies the number of characters to be deleted <strong>before</strong> the current cursor position</li><li>The second one specifies the number of characters to be deleted <strong>after</strong> the cursor</li></ul></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-176"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-174">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-175'
	>
	Good thing with this one is there’s no <code>IndexOutOfBoundsException</code> thrown here, so if you pass in an int value that is too large, the method will take care of it, and wipe out all characters in the specified range.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-179"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-177">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-178'
	>
	With that out of the way, let’s improve our <code>keyPadListener</code> implementation:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-181"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-java github-light" data-language="java" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token">val inputConnection </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #24292e;">currentlyFocusedEditText</span><span class="token">.</span><span class="token" style="color: #6f42c1;">onCreateInputConnection</span><span class="token">(</span><span class="token" style="color: #6f42c1;">EditorInfo</span><span class="token">(</span><span class="token">)</span><span class="token">)</span><span class="token"> 
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">private</span><span class="token"> val keyPadListener </span><span class="token" style="color: #d73a49;">=</span><span class="token"> OnClickListener </span><span class="token">{</span><span class="token"> view </span><span class="token" style="color: #d73a49;">-&gt;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #6f42c1;">when</span><span class="token"> </span><span class="token">(</span><span class="token" style="color: #24292e;">view</span><span class="token">.</span><span class="token" style="color: #24292e;">id</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #24292e;">R</span><span class="token">.</span><span class="token" style="color: #24292e;">id</span><span class="token">.</span><span class="token" style="color: #24292e;">deleteKey</span><span class="token" style="color: #d73a49;">-&gt;</span><span class="token"> inputConnection</span><span class="token" style="color: #d73a49;">?</span><span class="token">.</span><span class="token" style="color: #6f42c1;">delete</span><span class="token">(</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #d73a49;">else</span><span class="token"> </span><span class="token" style="color: #d73a49;">-&gt;</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   val value </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token">(</span><span class="token">view as</span><span class="token" style="color: #d73a49;">?</span><span class="token"> TextView</span><span class="token">)</span><span class="token" style="color: #d73a49;">?</span><span class="token">.</span><span class="token" style="color: #24292e;">text</span><span class="token">
</span></span><span class="line"><span class="token">   inputConnection</span><span class="token" style="color: #d73a49;">?</span><span class="token">.</span><span class="token" style="color: #6f42c1;">commitText</span><span class="token">(</span><span class="token">value</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">1</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">private</span><span class="token"> fun </span><span class="token" style="color: #24292e;">InputConnection</span><span class="token">.</span><span class="token" style="color: #6f42c1;">delete</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">if</span><span class="token"> </span><span class="token">(</span><span class="token" style="color: #6f42c1;">getSelectedText</span><span class="token">(</span><span class="token" style="color: #005cc5;">0</span><span class="token">)</span><span class="token">.</span><span class="token" style="color: #6f42c1;">isNullOrBlank</span><span class="token">(</span><span class="token">)</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #6f42c1;">deleteSurroundingText</span><span class="token">(</span><span class="token" style="color: #005cc5;">1</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">0</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token"> </span><span class="token" style="color: #d73a49;">else</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #6f42c1;">commitText</span><span class="token">(</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token"> </span><span class="token" style="color: #005cc5;">1</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-184"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-182">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-183'
	>
	This pretty much covers all the basic work we must do here.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-187"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-185">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-186'
	>
	Of course, I’m leaving all the nitty gritty details like setting the <code>keyPadListener</code> on your desired view or hiding system keyboard and all the use case-specific stuff to you.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-190"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-188">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-189'
	>
	Don’t overlook these either</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-193"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-191">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-192'
	>
	Remember, if you were to implement your own editor view, then you would need to subclass <code>BaseInputConnection</code> class to be able to use it.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-196"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-194">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-195'
	>
	Also, keep in mind that the <code>InputConnection</code> interface has around 26 methods you can use, and we covered only the most basic ones here.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-199"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-197">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-198'
	>
	A couple of other methods worth highlighting:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-202"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="lists" data-id="es-200">
	<ul	class='typography typography--size-16-text-roman js-typography lists__typography'
	data-id='es-201'
	>
	<li><em>setSelection(int, int)</em> which returns a boolean if the start selection index and end selection index passed in values are satisfied (the text has been successfully selected)</li><li><em>commitCompletion(CompletionInfo())</em> which returns a boolean which gives you another form of confirmation that your commit did in fact succeed and was displayed on your editor.</li></ul></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-205"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-203">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-204'
	>
	Further reading suggestions</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-208"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-206">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-207'
	>
	There is much to be shown or talked about regarding <code>InputConnection</code>, so I advise you to check out the <a href="https://developer.android.com/reference/android/view/inputmethod/InputConnection">full documentation</a> for this powerful interface.</p></div>	</div>
</div>
</div>		</div>
	</div><p>The post <a href="https://infinum.com/blog/input-connection/">Easy Custom Keyboard with InputConnection</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</content:encoded>
			</item>
		
	</channel>
</rss>