<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Making a custom Android button using a custom view</title>
	<atom:link href="http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/feed/" rel="self" type="application/rss+xml" />
	<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/</link>
	<description>The world of development ...</description>
	<lastBuildDate>Sun, 25 Oct 2009 12:42:27 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: kahgoh</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-168</link>
		<dc:creator>kahgoh</dc:creator>
		<pubDate>Wed, 17 Jun 2009 12:53:19 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-168</guid>
		<description>I mentioned in a previous reply that the height and width of the view are determined by the call to &lt;strong&gt;onMeasure()&lt;/strong&gt;, which delegates to &lt;strong&gt;measureHeight()&lt;/strong&gt; and &lt;strong&gt;measureWidth()&lt;/strong&gt; so you can change these methods to account for the text. For more information, see &lt;a href=&quot;http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-166&quot; rel=&quot;nofollow&quot;&gt;this previous comment&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>I mentioned in a previous reply that the height and width of the view are determined by the call to <strong>onMeasure()</strong>, which delegates to <strong>measureHeight()</strong> and <strong>measureWidth()</strong> so you can change these methods to account for the text. For more information, see <a href="http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-166" rel="nofollow">this previous comment</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Snowdrop</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-167</link>
		<dc:creator>Snowdrop</dc:creator>
		<pubDate>Wed, 17 Jun 2009 04:06:20 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-167</guid>
		<description>Can the custom button be freely resizable instead of hard coding it ? Meaning, if the Button caption is not one, but two lines high, how does the background adapt?</description>
		<content:encoded><![CDATA[<p>Can the custom button be freely resizable instead of hard coding it ? Meaning, if the Button caption is not one, but two lines high, how does the background adapt?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kahgoh</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-166</link>
		<dc:creator>kahgoh</dc:creator>
		<pubDate>Tue, 16 Jun 2009 12:33:27 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-166</guid>
		<description>Like I said, I haven&#039;t tried this myself, therefore I haven&#039;t written the code. I&#039;m merely suggesting a possible way of attempting it, but I haven&#039;t tried, tested or verified it myself. However, to provide a quick summary of what I was thinking of.

Start by creating your own &lt;strong&gt;View.OnTouchListener&lt;/strong&gt;.  This will calculate and determine whether the click should be actioned or not.
&lt;pre&gt;
  public class AreaVeto implements View.OnTouchListener {
    public boolean onTouch(View v, MotionEvent event) {
       // Calculation here. 

      return ... // Use false if click is within area?
    }
  }
&lt;/pre&gt;

For calculating whether the click is within the area, the &lt;strong&gt;MotionEvent&lt;/strong&gt; parameters have &lt;strong&gt;getX()&lt;/strong&gt; and &lt;strong&gt;getY()&lt;/strong&gt; to tell you where the click has occured. Because a calculation is being performed, dealing with buttons of any random shape would be more complex. If you are using an image with trasparent background, perhaps you can try calling &lt;strong&gt;Bitmap.getPixel()&lt;/strong&gt; to get the colour at the location to decide whether it is within the clickable area. Obviously, this also implies that the listener needs to know about the bitmap.

After creating your listener, you need to set it as the touch listener. This is done by calling the &lt;strong&gt;View.setOnTouchListener()&lt;/strong&gt; method. You can call this method from within the customised view class or after your view is created.

Hopefully, this will give you a clearer idea of what I was thinking of.</description>
		<content:encoded><![CDATA[<p>Like I said, I haven&#8217;t tried this myself, therefore I haven&#8217;t written the code. I&#8217;m merely suggesting a possible way of attempting it, but I haven&#8217;t tried, tested or verified it myself. However, to provide a quick summary of what I was thinking of.</p>
<p>Start by creating your own <strong>View.OnTouchListener</strong>.  This will calculate and determine whether the click should be actioned or not.</p>
<pre>
  public class AreaVeto implements View.OnTouchListener {
    public boolean onTouch(View v, MotionEvent event) {
       // Calculation here. 

      return ... // Use false if click is within area?
    }
  }
</pre>
<p>For calculating whether the click is within the area, the <strong>MotionEvent</strong> parameters have <strong>getX()</strong> and <strong>getY()</strong> to tell you where the click has occured. Because a calculation is being performed, dealing with buttons of any random shape would be more complex. If you are using an image with trasparent background, perhaps you can try calling <strong>Bitmap.getPixel()</strong> to get the colour at the location to decide whether it is within the clickable area. Obviously, this also implies that the listener needs to know about the bitmap.</p>
<p>After creating your listener, you need to set it as the touch listener. This is done by calling the <strong>View.setOnTouchListener()</strong> method. You can call this method from within the customised view class or after your view is created.</p>
<p>Hopefully, this will give you a clearer idea of what I was thinking of.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kahgoh</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-165</link>
		<dc:creator>kahgoh</dc:creator>
		<pubDate>Tue, 16 Jun 2009 12:08:38 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-165</guid>
		<description>Firstly, if you read the documentation the method &lt;strong&gt;onMeasure()&lt;/strong&gt; is the method that is called to obtain measurements for contents. In my implementation, this gets delegated to &lt;strong&gt;measureWidth()&lt;/strong&gt; and &lt;strong&gt;measureHeight()&lt;/strong&gt;, so you can modify just two functions to calculate their measurements based on the text. At this stage, I&#039;ve also have not looked into how to obtain the pixel width or height of a text label but this technique might help: &lt;a href=&quot;http://www.mail-archive.com/android-developers@googlegroups.com/msg18526.html&quot; rel=&quot;nofollow&quot;&gt;http://www.mail-archive.com/android-developers@googlegroups.com/msg18526.html&lt;/a&gt;

Secondly, I assume you are asking how to change the text. The custom view actually takes in the text label for the button as an argument to its constructor. If you are talking about the positioning of the text, look at &lt;strong&gt;onDraw()&lt;/strong&gt;. Documentation states:

    &lt;em&gt;Method called on to render the view.&lt;/em&gt;

It is also here that I draw the text with the call to &lt;strong&gt;canvas.drawText()&lt;/strong&gt;.</description>
		<content:encoded><![CDATA[<p>Firstly, if you read the documentation the method <strong>onMeasure()</strong> is the method that is called to obtain measurements for contents. In my implementation, this gets delegated to <strong>measureWidth()</strong> and <strong>measureHeight()</strong>, so you can modify just two functions to calculate their measurements based on the text. At this stage, I&#8217;ve also have not looked into how to obtain the pixel width or height of a text label but this technique might help: <a href="http://www.mail-archive.com/android-developers@googlegroups.com/msg18526.html" rel="nofollow">http://www.mail-archive.com/android-developers@googlegroups.com/msg18526.html</a></p>
<p>Secondly, I assume you are asking how to change the text. The custom view actually takes in the text label for the button as an argument to its constructor. If you are talking about the positioning of the text, look at <strong>onDraw()</strong>. Documentation states:</p>
<p>    <em>Method called on to render the view.</em></p>
<p>It is also here that I draw the text with the call to <strong>canvas.drawText()</strong>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shyam</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-164</link>
		<dc:creator>Shyam</dc:creator>
		<pubDate>Mon, 15 Jun 2009 19:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-164</guid>
		<description>I tried doing this but I could not set the clickable area. Could you please send me a code for that and where to insert it?

Thanks in advance for your help


kahgoh
10 June, 2009 at 8:45 pm 

I’ve never tried this myself, but I would probably start by looking at overriding onTouchEvent(). It receives a MotionEvent object that has information about the X and Y co-ordinates, so from there I believe you should be able to control whether the event gets processed or not.</description>
		<content:encoded><![CDATA[<p>I tried doing this but I could not set the clickable area. Could you please send me a code for that and where to insert it?</p>
<p>Thanks in advance for your help</p>
<p>kahgoh<br />
10 June, 2009 at 8:45 pm </p>
<p>I’ve never tried this myself, but I would probably start by looking at overriding onTouchEvent(). It receives a MotionEvent object that has information about the X and Y co-ordinates, so from there I believe you should be able to control whether the event gets processed or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hima Bindu</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-163</link>
		<dc:creator>Hima Bindu</dc:creator>
		<pubDate>Mon, 15 Jun 2009 16:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-163</guid>
		<description>Can we make the custom image button (in your code) according to the text we write (for example : Instead of Painting I want to add &quot;This is a button of a painting &quot;) and the entire text should be displayed on the button below the image.

Could you please tell me where and what code should be inserted to extend the button to fit the text?</description>
		<content:encoded><![CDATA[<p>Can we make the custom image button (in your code) according to the text we write (for example : Instead of Painting I want to add &#8220;This is a button of a painting &#8220;) and the entire text should be displayed on the button below the image.</p>
<p>Could you please tell me where and what code should be inserted to extend the button to fit the text?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kahgoh</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-161</link>
		<dc:creator>kahgoh</dc:creator>
		<pubDate>Wed, 10 Jun 2009 12:45:54 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-161</guid>
		<description>I&#039;ve never tried this myself, but I would probably start by looking at overriding onTouchEvent(). It receives a MotionEvent object that has information about the X and Y co-ordinates, so from there I believe you should be able to control whether the event gets processed or not.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve never tried this myself, but I would probably start by looking at overriding onTouchEvent(). It receives a MotionEvent object that has information about the X and Y co-ordinates, so from there I believe you should be able to control whether the event gets processed or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hima Bindu</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-160</link>
		<dc:creator>Hima Bindu</dc:creator>
		<pubDate>Wed, 10 Jun 2009 10:03:12 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-160</guid>
		<description>Can we set the clickable area of a button? Could you please tell me where in the code I could add the clickable area if we can set it at all?</description>
		<content:encoded><![CDATA[<p>Can we set the clickable area of a button? Could you please tell me where in the code I could add the clickable area if we can set it at all?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hima Bindu</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-159</link>
		<dc:creator>Hima Bindu</dc:creator>
		<pubDate>Thu, 04 Jun 2009 08:31:41 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-159</guid>
		<description>Thanks a lot for the reply</description>
		<content:encoded><![CDATA[<p>Thanks a lot for the reply</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kahgoh</title>
		<link>http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/#comment-158</link>
		<dc:creator>kahgoh</dc:creator>
		<pubDate>Wed, 03 Jun 2009 14:03:40 +0000</pubDate>
		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=60#comment-158</guid>
		<description>Changing the font is as easy as creating a Typeface object and setting the paint to use the font (see Typeface.setTypeface()). I&#039;ll probably write an entry about it when I get the chance to. As for changing the state, you could possibly look at overriding onKeyDown and onKeyUp.</description>
		<content:encoded><![CDATA[<p>Changing the font is as easy as creating a Typeface object and setting the paint to use the font (see Typeface.setTypeface()). I&#8217;ll probably write an entry about it when I get the chance to. As for changing the state, you could possibly look at overriding onKeyDown and onKeyUp.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
